From a66f20b098a3b24bae59bdef0184678118553785 Mon Sep 17 00:00:00 2001 From: Justin Obara Date: Tue, 21 Nov 2023 14:50:43 -0500 Subject: [PATCH] fix: sitemap command fails if pages table missing --- .kube/app/entrypoint.sh | 3 +++ app/Console/Commands/DeployLocal.php | 1 - app/Console/Commands/GenerateSitemap.php | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.kube/app/entrypoint.sh b/.kube/app/entrypoint.sh index 86897f692..183331ad9 100755 --- a/.kube/app/entrypoint.sh +++ b/.kube/app/entrypoint.sh @@ -31,4 +31,7 @@ flock -n -E 0 /opt/data -c "php artisan deploy:global" # run exclusively on a si ## fix permissions after syncing to existing storage and cache https://github.com/accessibility-exchange/platform/issues/1236 chown -R www-data:root /app/bootstrap/cache $FILES_PATH # $CACHE_PATH removed per and added path to cache in the pod https://github.com/accessibility-exchange/platform/issues/1596 +# Generate the robots.txt and sitemap.xml files +php artisan seo:generate + /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf diff --git a/app/Console/Commands/DeployLocal.php b/app/Console/Commands/DeployLocal.php index a49909b5d..efe3ad951 100644 --- a/app/Console/Commands/DeployLocal.php +++ b/app/Console/Commands/DeployLocal.php @@ -31,6 +31,5 @@ public function handle() $this->call('icons:cache'); $this->call('event:cache'); $this->call('optimize'); - $this->call('seo:generate'); } } diff --git a/app/Console/Commands/GenerateSitemap.php b/app/Console/Commands/GenerateSitemap.php index 2bbf4868d..8ca4b82b8 100644 --- a/app/Console/Commands/GenerateSitemap.php +++ b/app/Console/Commands/GenerateSitemap.php @@ -6,6 +6,7 @@ use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Support\Facades\Route; +use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Storage; class GenerateSitemap extends Command @@ -34,6 +35,7 @@ public function handle() $routes = ['/' => ['en' => 'en', 'asl' => 'asl', 'fr' => 'fr', 'lsq' => 'lsq']]; // once deployed to the server, files have the same modified date, use README as a default last modified date $lastmod = ['default' => Carbon::createFromTimestamp(filemtime('./README.md'))->toISOString()]; + $hasPages = Schema::hasTable('pages'); // Check if the Pages table exists. foreach (Route::getRoutes()->get('GET') as $route) { if ($route->named(config('seo.sitemap.patterns'))) { $routeURI = $route->uri(); @@ -42,7 +44,7 @@ public function handle() $routes[$url][$locale] = $routeURI; } else { $routes[$url] = [$locale => $routeURI]; - if ($route->named(config('seo.sitemap.pages'))) { + if ($route->named(config('seo.sitemap.pages')) && $hasPages) { $routeName = explode('.', $route->getName()); /* * TODO: come up with better query for the page, as slug may not follow the pattern in route name