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\Support\Facades\DB;
class WorkshopMigration extends CubistCommand
{
- protected $signature = 'ws:migrate';
+ protected $signature = 'ws:migrate {--publications=v2} {--documents=v2}';
protected $description = 'Migrate data from Workshop V2';
protected $_wsRanks = [];
protected $_oldDB = 'extranet_clean';
$this->executeProcessQuiet('/usr/bin/php8.0 artisan optimize:clear');
}
- protected function importDocuments($reset = true)
+ protected function importDocuments()
{
+ if($this->option('documents')==='none'){
+ return;
+ }
+
PHP::neverStop();
$ws3step = 200000;
- if ($reset) {
+ $q = DB::table($this->_oldDB . '.documents')->orderBy('document_id', 'desc');
+
+ if ($this->option('documents') === 'v2') {
+ DB::update('DELETE FROM fluidbook_document WHERE id<' . $ws3step);
+ } else if ($this->option('documents') === 'all') {
FluidbookDocument::truncate();
} else {
- DB::update('DELETE FROM fluidbook_document WHERE id<' . $ws3step);
+ $range = ArrayUtil::parseRange($this->option('documents'));
+ FluidbookDocument::whereIn('id', $range)->delete();
+ $q->whereIn('document_id', $range);
}
- foreach (DB::table($this->_oldDB . '.documents')->orderBy('document_id', 'desc')->get() as $e) {
+
+ foreach ($q->get() as $e) {
$this->line('Import ' . $e->document_id);
$c = new FluidbookDocument();
$c->setIncrementing(false);
$c->bookmarks = $this->_migrateBookmarks($e->bookmarks);
$c->saveWithoutFlushingCache();
}
- if ($reset) {
+ if ($this->option('documents') === 'all') {
DB::update('ALTER TABLE ' . $c->getTable() . ' AUTO_INCREMENT = ' . $ws3step . ';');
}
}
protected function importPublications($reset = false)
{
+ if($this->option('publications')==='none'){
+ return;
+ }
+
PHP::neverStop();
$ws3step = 30000;
$this->line('Begin publications migration');
FluidbookTheme::$updateWS2ViewOnChange = false;
-// foreach (FluidbookPublication::lazy() as $book) {
-// $this->line('Delete ' . $book->id);
-// $book->delete();
-// }
- if ($reset) {
+
+ $q = DB::table($this->_oldDB . '.books')->orderBy('book_id', 'asc');
+
+ if ($this->option('publications') === 'v2') {
+ DB::update('DELETE FROM fluidbook_publication WHERE id<' . $ws3step);
+ } else if ($this->option('publications') === 'all') {
FluidbookPublication::truncate();
} else {
- DB::update('DELETE FROM fluidbook_publication WHERE id<' . $ws3step);
+ $range = ArrayUtil::parseRange($this->option('publications'));
+ FluidbookPublication::whereIn('id', $range)->delete();
+ $q->whereIn('book_id', $range);
}
-
- foreach (DB::table($this->_oldDB . '.books')->orderBy('book_id', 'asc')->get() as $e) {
+ foreach ($q->get() as $e) {
$this->line('Import ' . $e->book_id);
$oldRoot = $this->_oldRoot . 'books/working/' . $e->book_id . '/';
$c = new FluidbookPublication();
$date = new \DateTime();
$date->setTimestamp($data);
$data = $date;
- } else if ($k === 'chapters') {
+ } else if ($k == 'chapters') {
$data = $this->_normalizeChapters($data);
}
if (isset($mapValues[$data])) {