From eb5e853f2d0fef584403d81045310c2b3488568c Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 17 Nov 2022 11:31:24 +0100 Subject: [PATCH 1/8] fix: migration for stats region --- src/Appwrite/Migration/Version/V16.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Migration/Version/V16.php b/src/Appwrite/Migration/Version/V16.php index 311cbaff2c..db13e6d182 100644 --- a/src/Appwrite/Migration/Version/V16.php +++ b/src/Appwrite/Migration/Version/V16.php @@ -50,7 +50,7 @@ class V16 extends Migration case 'sessions': try { /** - * Create 'compression' attribute + * Create 'expire' attribute */ $this->projectDB->deleteAttribute($id, 'expire'); } catch (\Throwable $th) { @@ -79,6 +79,17 @@ class V16 extends Migration } break; + case 'stats': + try { + /** + * Create 'region' attribute + */ + $this->createAttributeFromCollection($this->projectDB, $id, 'region'); + } catch (\Throwable $th) { + Console::warning("'region' from {$id}: {$th->getMessage()}"); + } + break; + default: break; } From 00ec95fc9fc74dfb4707dced76e86ff2de596418 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 17 Nov 2022 11:35:29 +0100 Subject: [PATCH 2/8] chore: add changelog --- CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 2e24c74174..6385196d75 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,8 @@ -# Version TBD +# Version 1.1.1 ## Bugs - Fix Deletes worker using incorrect device for file deletion [#4662](https://github.com/appwrite/appwrite/pull/4662) +- Fix Migration for Stats adding the region attribute [#4704](https://github.com/appwrite/appwrite/pull/4704) # Version 1.1.0 ## Features From 30f088ad356778c0cc28b6b6448fb565e63a112b Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 17 Nov 2022 12:26:14 +0100 Subject: [PATCH 3/8] fix: cache cleaning on migration --- app/tasks/migrate.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/tasks/migrate.php b/app/tasks/migrate.php index f0ab71a964..1d155c210d 100644 --- a/app/tasks/migrate.php +++ b/app/tasks/migrate.php @@ -9,10 +9,20 @@ use Utopia\Cache\Cache; use Utopia\Cache\Adapter\Redis as RedisCache; use Utopia\Database\Adapter\MariaDB; use Utopia\Database\Database; +use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Validator\Text; +function clearProjectsCache(Redis $redis, Document $project) +{ + try { + $redis->del($redis->keys("cache-_{$project->getInternalId()}:*")); + } catch (\Throwable $th) { + Console::error('Failed to clear project ("' . $project->getId() . '") cache with error: ' . $th->getMessage()); + } +} + $cli ->task('migrate') ->param('version', APP_VERSION_STABLE, new Text(32), 'Version to migrate to.', true) @@ -30,7 +40,7 @@ $cli $db = $register->get('db', true); $redis = $register->get('cache', true); - $redis->flushAll(); + $cache = new Cache(new RedisCache($redis)); $projectDB = new Database(new MariaDB($db), $cache); @@ -70,6 +80,8 @@ $cli continue; } + clearProjectsCache($redis, $project); + try { $migration ->setProject($project, $projectDB, $consoleDB) @@ -78,6 +90,8 @@ $cli throw $th; Console::error('Failed to update project ("' . $project->getId() . '") version with error: ' . $th->getMessage()); } + + clearProjectsCache($redis, $project); } $sum = \count($projects); @@ -90,6 +104,5 @@ $cli } Swoole\Event::wait(); // Wait for Coroutines to finish - $redis->flushAll(); Console::success('Data Migration Completed'); }); From 6567b23c85eb3ad93a755a1e43887ba74450c342 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 17 Nov 2022 12:26:58 +0100 Subject: [PATCH 4/8] chore: update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 6385196d75..05b64ec242 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ ## Bugs - Fix Deletes worker using incorrect device for file deletion [#4662](https://github.com/appwrite/appwrite/pull/4662) - Fix Migration for Stats adding the region attribute [#4704](https://github.com/appwrite/appwrite/pull/4704) +- Fix Migration stopping scheduled functions [#4704](https://github.com/appwrite/appwrite/pull/4704) # Version 1.1.0 ## Features From 53adb4e1142df5fcd87bbfc007a9505375714b19 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 17 Nov 2022 12:38:09 +0100 Subject: [PATCH 5/8] fix: migration for oauth providers --- src/Appwrite/Migration/Version/V16.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Appwrite/Migration/Version/V16.php b/src/Appwrite/Migration/Version/V16.php index db13e6d182..070b8e7d92 100644 --- a/src/Appwrite/Migration/Version/V16.php +++ b/src/Appwrite/Migration/Version/V16.php @@ -5,6 +5,7 @@ namespace Appwrite\Migration\Version; use Appwrite\Auth\Auth; use Appwrite\Migration\Migration; use Utopia\CLI\Console; +use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\Document; @@ -119,6 +120,20 @@ class V16 extends Migration $document->setAttribute('auths', array_merge($document->getAttribute('auths', []), [ 'duration' => Auth::TOKEN_EXPIRATION_LOGIN_LONG ])); + + + $authProviders = $document->getAttribute('authProviders', []); + + foreach (Config::getParam('providers') as $provider => $value) { + if (!$value['enabled']) { + continue; + } + + if (($authProviders[$provider . 'Appid'] ?? false) && ($authProviders[$provider . 'Secret'] ?? false)) { + $authProviders[$provider . 'Enabled'] = true; + } + } + break; } From e7189efcff44bc8ea8a4ee16f309f16bfbde18e6 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 17 Nov 2022 12:38:39 +0100 Subject: [PATCH 6/8] chore: update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 05b64ec242..401af0ef6c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ - Fix Deletes worker using incorrect device for file deletion [#4662](https://github.com/appwrite/appwrite/pull/4662) - Fix Migration for Stats adding the region attribute [#4704](https://github.com/appwrite/appwrite/pull/4704) - Fix Migration stopping scheduled functions [#4704](https://github.com/appwrite/appwrite/pull/4704) +- Fix Migration enabling OAuth providers with data by default [#4704](https://github.com/appwrite/appwrite/pull/4704) # Version 1.1.0 ## Features From 8d3903cd37ad7744077c31a961206c41792958c2 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 17 Nov 2022 13:37:59 +0100 Subject: [PATCH 7/8] fix: remove layout --- app/controllers/general.php | 17 ++------ app/controllers/shared/web.php | 64 ---------------------------- app/init.php | 7 --- app/views/general/error.phtml | 78 ++++++++++++++++++++-------------- 4 files changed, 51 insertions(+), 115 deletions(-) delete mode 100644 app/controllers/shared/web.php diff --git a/app/controllers/general.php b/app/controllers/general.php index 48c80ab736..069a918680 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -394,11 +394,10 @@ App::error() ->inject('utopia') ->inject('request') ->inject('response') - ->inject('layout') ->inject('project') ->inject('logger') ->inject('loggerBreadcrumbs') - ->action(function (Throwable $error, App $utopia, Request $request, Response $response, View $layout, Document $project, ?Logger $logger, array $loggerBreadcrumbs) { + ->action(function (Throwable $error, App $utopia, Request $request, Response $response, Document $project, ?Logger $logger, array $loggerBreadcrumbs) { $version = App::getEnv('_APP_VERSION', 'UNKNOWN'); $route = $utopia->match($request); @@ -538,9 +537,10 @@ App::error() $template = ($route) ? $route->getLabel('error', null) : null; if ($template) { - $comp = new View($template); + $layout = new View($template); - $comp + $layout + ->setParam('title', $project->getAttribute('name') . ' - Error') ->setParam('development', App::isDevelopment()) ->setParam('projectName', $project->getAttribute('name')) ->setParam('projectURL', $project->getAttribute('url')) @@ -549,14 +549,6 @@ App::error() ->setParam('trace', $trace) ; - $layout - ->setParam('title', $project->getAttribute('name') . ' - Error') - ->setParam('description', 'No Description') - ->setParam('body', $comp) - ->setParam('version', $version) - ->setParam('litespeed', false) - ; - $response->html($layout->render()); } @@ -637,7 +629,6 @@ App::get('/.well-known/acme-challenge') }); include_once __DIR__ . '/shared/api.php'; -include_once __DIR__ . '/shared/web.php'; foreach (Config::getParam('services', []) as $service) { include_once $service['controller']; diff --git a/app/controllers/shared/web.php b/app/controllers/shared/web.php deleted file mode 100644 index 5e1e0bd370..0000000000 --- a/app/controllers/shared/web.php +++ /dev/null @@ -1,64 +0,0 @@ -groups(['web']) - ->inject('utopia') - ->inject('request') - ->inject('response') - ->inject('layout') - ->action(function (App $utopia, Request $request, Response $response, View $layout) { - /* AJAX check */ - if (!empty($request->getQuery('version', ''))) { - $layout->setPath(__DIR__ . '/../../views/layouts/empty.phtml'); - } - - $port = $request->getPort(); - $protocol = $request->getProtocol(); - $domain = $request->getHostname(); - - $layout - ->setParam('title', APP_NAME) - ->setParam('protocol', $protocol) - ->setParam('domain', $domain) - ->setParam('endpoint', $protocol . '://' . $domain . ($port != 80 && $port != 443 ? ':' . $port : '')) - ->setParam('home', App::getEnv('_APP_HOME')) - ->setParam('setup', App::getEnv('_APP_SETUP')) - ->setParam('class', 'unknown') - ->setParam('icon', '/images/favicon.png') - ->setParam('roles', [ - ['type' => 'owner', 'label' => 'Owner'], - ['type' => 'developer', 'label' => 'Developer'], - ['type' => 'admin', 'label' => 'Admin'], - ]) - ->setParam('runtimes', Config::getParam('runtimes')) - ->setParam('mode', App::getMode()) - ; - - $time = (60 * 60 * 24 * 45); // 45 days cache - - $response - ->addHeader('Cache-Control', 'public, max-age=' . $time) - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $time) . ' GMT') // 45 days cache - ->addHeader('X-Frame-Options', 'SAMEORIGIN') // Avoid console and homepage from showing in iframes - ->addHeader('X-XSS-Protection', '1; mode=block; report=/v1/xss?url=' . \urlencode($request->getURI())) - ->addHeader('X-UA-Compatible', 'IE=Edge') // Deny IE browsers from going into quirks mode - ; - - $route = $utopia->match($request); - - $route->label('error', __DIR__ . '/../../views/general/error.phtml'); - - $scope = $route->getLabel('scope', ''); - - $layout - ->setParam('version', App::getEnv('_APP_VERSION', 'UNKNOWN')) - ->setParam('isDev', App::isDevelopment()) - ->setParam('class', $scope) - ; - }); diff --git a/app/init.php b/app/init.php index f502896148..c9a6097ab4 100644 --- a/app/init.php +++ b/app/init.php @@ -730,13 +730,6 @@ App::setResource('loggerBreadcrumbs', function () { App::setResource('register', fn() => $register); -App::setResource('layout', function ($locale) { - $layout = new View(__DIR__ . '/views/layouts/default.phtml'); - $layout->setParam('locale', $locale); - - return $layout; -}, ['locale']); - App::setResource('locale', fn() => new Locale(App::getEnv('_APP_LOCALE', 'en'))); // Queues diff --git a/app/views/general/error.phtml b/app/views/general/error.phtml index 66f6cf77d7..d5a11246f7 100644 --- a/app/views/general/error.phtml +++ b/app/views/general/error.phtml @@ -6,44 +6,60 @@ $message = $this->getParam('message', ''); $trace = $this->getParam('trace', []); $projectName = $this->getParam('projectName', ''); $projectURL = $this->getParam('projectURL', ''); +$title = $this->getParam('title', '') ?> -
-

Error

+ + -

+ + + + + <?php echo $title; ?> + - Error ID: + - -
+
+

Error

-

Back to

- +

- -
- -

Error Trace

+ Error ID: + + +
+ +

Back to

+ + + +
+ +

Error Trace

+ + + + $value) : ?> + + + + - -
+ + + + + +
- $value): ?> - - - - - -
- - - - - -
- -
- + + +
+ -
+
+ + + \ No newline at end of file From a252c7e46906b73d6c67f2c83bec5d2e58913d2f Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 17 Nov 2022 13:39:16 +0100 Subject: [PATCH 8/8] chore: update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 401af0ef6c..6b7af775de 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ - Fix Migration for Stats adding the region attribute [#4704](https://github.com/appwrite/appwrite/pull/4704) - Fix Migration stopping scheduled functions [#4704](https://github.com/appwrite/appwrite/pull/4704) - Fix Migration enabling OAuth providers with data by default [#4704](https://github.com/appwrite/appwrite/pull/4704) +- Fix Error pages when OAuth providers are disabled [#4704](https://github.com/appwrite/appwrite/pull/4704) # Version 1.1.0 ## Features