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
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',
$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()
$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);
}
}
return $res;
}
+
+ public function __destruct()
+ {
+
+ }
}