]> _ Git - pmi.git/commitdiff
wip #3013 @0:10
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 6 Sep 2019 15:16:57 +0000 (17:16 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 6 Sep 2019 15:16:57 +0000 (17:16 +0200)
app/Console/Commands/CMSMigration.php

index 09dfd3a8b48e0714c3acc89aefc22c1e0feadb9e..afde3a22a559d87b785a3b31b31ddd9faa162096 100644 (file)
@@ -9,12 +9,13 @@ use Illuminate\Support\Facades\DB;
 
 class CMSMigration extends Command
 {
-    protected $signature = 'pmi:exportcmsdatatostaging';
+    protected $signature = 'pmi:exportcmsdatafromstaging';
     protected $description = 'Export CMS data filed in dev to staging';
 
     public function handle()
     {
         echo 'Run backup of staging' . "\n";
+        `cd /home/pmi/dev;php artisan backup:run`;
         `cd /home/pmi/www;php artisan backup:run`;
 
         $tables = ['cubist_cms_pages', 'cubist_news', 'cubist_settings', 'cubist_locales', 'cubist_translate', 'applications'];
@@ -26,45 +27,43 @@ class CMSMigration extends Command
 
         foreach ($tables as $table) {
             echo 'Copy table ' . $table . ' from dev to staging' . "\n";
-            DB::statement('DROP TABLE pmi.' . $table);
-            DB::statement('CREATE TABLE pmi.' . $table . ' LIKE pmi_dev.' . $table);
-            DB::statement('INSERT pmi.' . $table . ' SELECT * FROM pmi_dev.' . $table);
+            DB::statement('DROP TABLE pmi_dev.' . $table);
+            DB::statement('CREATE TABLE pmi_dev.' . $table . ' LIKE pmi.' . $table);
+            DB::statement('INSERT pmi_dev.' . $table . ' SELECT * FROM pmi.' . $table);
         }
 
         echo 'Remove old media from staging' . "\n";
-        $sql = 'SELECT * FROM pmi.media WHERE model_type IN (' . $modelssql . ')';
+        $sql = 'SELECT * FROM pmi_dev.media WHERE model_type IN (' . $modelssql . ')';
         foreach (DB::select($sql) as $item) {
             $item = ArrayUtil::asArray($item);
 
-            $rm = 'rm -rf /home/pmi/www/public/storage/' . $item['id'];
-            echo 'Delete storage ' . $item['id'] . ' on staging' . "\n";
+            $rm = 'rm -rf /home/pmi/dev/public/storage/' . $item['id'];
+            echo 'Delete storage ' . $item['id'] . ' on dev' . "\n";
             `$rm`;
         }
-        DB::delete('DELETE FROM pmi.media WHERE model_type IN (' . $modelssql . ')');
+        DB::delete('DELETE FROM pmi_dev.media WHERE model_type IN (' . $modelssql . ')');
 
-        echo 'Copy media from dev to staging' . "\n";
-        foreach (DB::select('SELECT * FROM pmi_dev.media WHERE model_type IN(' . $modelssql . ')') as $item) {
+        echo 'Copy media from staging to dev' . "\n";
+        foreach (DB::select('SELECT * FROM pmi.media WHERE model_type IN(' . $modelssql . ')') as $item) {
             $item = ArrayUtil::asArray($item);
 
             $devId = $item['id'];
             unset($item['id']);
 
-            $id = DB::table('pmi.media')->insertGetId($item);
+            $id = DB::table('pmi_dev.media')->insertGetId($item);
             echo 'Copy files from dev #' . $devId . ' to staging #' . $id . "\n";
-            $dest = '/home/pmi/www/public/storage/' . $id;
+            $dest = '/home/pmi/dev/public/storage/' . $id;
             if (file_exists($dest)) {
                 $destprotect = $dest . '_';
                 `mv $dest $destprotect`;
             }
-            $cp = 'cp -R /home/pmi/dev/public/storage/' . $devId . ' /home/pmi/www/public/storage/' . $id;
+            $cp = 'cp -R /home/pmi/www/public/storage/' . $devId . ' /home/pmi/dev/public/storage/' . $id;
             echo $cp . ' : ' . `$cp` . "\n";
         }
 
-        echo 'Update code of staging' . "\n";
-        `cd /home/pmi/www;php update`;
-        echo 'Clear caches of staging' . "\n";
-        `cd /home/pmi/www;php artisan cache:clear`;
-        `cd /home/pmi/www;php artisan config:cache`;
-        `cd /home/pmi/www;php artisan view:cache`;
+        echo 'Clear caches of dev' . "\n";
+        `cd /home/pmi/dev;php artisan cache:clear`;
+        `cd /home/pmi/dev;php artisan config:cache`;
+        `cd /home/pmi/dev;php artisan view:cache`;
     }
 }