From: Vincent Vanwaelscappel Date: Fri, 25 Aug 2023 15:23:48 +0000 (+0200) Subject: wait #6091 @0.75 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=49032c6e588439147ecb0ac27c286e720d6bd5c9;p=fluidbook-toolbox.git wait #6091 @0.75 --- diff --git a/app/Console/Commands/WorkshopMigration.php b/app/Console/Commands/WorkshopMigration.php index 02204b35e..63471d699 100644 --- a/app/Console/Commands/WorkshopMigration.php +++ b/app/Console/Commands/WorkshopMigration.php @@ -3,20 +3,18 @@ namespace App\Console\Commands; -use App\Models\AuthUser; use App\Models\FluidbookDocument; use App\Models\FluidbookPublication; -use App\Models\FluidbookQuote; use App\Models\FluidbookTheme; use Cubist\Backpack\Console\Commands\CubistCommand; use Cubist\Backpack\Magic\Fields\Color; -use Cubist\Backpack\Magic\Fields\Date; use Cubist\Backpack\Magic\Fields\Datetime; -use Cubist\Backpack\Magic\Fields\Files; use Cubist\Util\ArrayUtil; use Cubist\Util\ObjectUtil; use Cubist\Util\PHP; +use Illuminate\Contracts\Cache\Lock; use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; class WorkshopMigration extends CubistCommand @@ -28,11 +26,19 @@ class WorkshopMigration extends CubistCommand protected $_oldRoot = '/home/extranet/www/fluidbook/'; protected static $_admin = 5; + /** @var Lock */ + protected Lock $_lock; + const WS3_BOOK_ID = 30000; const WS3_DOC_ID = 200000; public function handle() { + $this->_lock = Cache::lock('ws2_migrate', 3600); + if (!$this->_lock->get()) { + return; + } + $actions = [ //'Backup current database' => 'backup', 'Migrate magic models' => 'migrate', @@ -50,14 +56,17 @@ class WorkshopMigration extends CubistCommand $this->line(' Data migration, please wait'); $this->progressBar->start(); - foreach ($actions as $comment => $action) { - $this->line($comment); - $this->$action(); - $this->progressBar->advance(); - } - - $this->line('End of import'); + try { + foreach ($actions as $comment => $action) { + $this->line($comment); + $this->$action(); + $this->progressBar->advance(); + } + $this->line('End of import'); + } finally { + $this->_lock->release(); + } } protected function migrate() @@ -199,14 +208,14 @@ class WorkshopMigration extends CubistCommand $q = DB::table(self::OLD_DB . '.books')->orderBy('book_id', 'asc'); if ($this->option('publications') === 'v2') { - DB::update('DELETE FROM fluidbook_publication WHERE version=2 AND id<' . self::WS3_BOOK_ID); + DB::update('DELETE FROM fluidbook_publication WHERE version <= 2 AND id<' . self::WS3_BOOK_ID); } else if ($this->option('publications') === 'missing') { // Get highest fluidbook on toolbox with a number less thant WS3_BOOK_ID $f = FluidbookPublication::withoutGlobalScopes()->where('id', '<', self::WS3_BOOK_ID)->orderBy('id', 'DESC')->first(); $q->where('book_id', '>', $f->id); } else { $range = ArrayUtil::parseRange($this->option('publications')); - FluidbookPublication::withoutGlobalScopes()->where('version', 2)->whereIn('id', $range)->delete(); + FluidbookPublication::withoutGlobalScopes()->where('version', '<=', 2)->whereIn('id', $range)->delete(); $q->whereIn('book_id', $range); } @@ -322,4 +331,9 @@ class WorkshopMigration extends CubistCommand } return $res; } + + public function __destruct() + { + + } }