--- /dev/null
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\FluidbookPublication;
+use Cubist\Backpack\Console\Commands\CubistCommand;
+use Illuminate\Support\Facades\DB;
+
+class ToolboxToWorkshop extends CubistCommand
+{
+ protected $signature = 'toolboxtows {id} {targetid=new}';
+ protected $description = 'Migrate a fluidbook made on the toolbox back to the workshop';
+
+ protected static $_wstable = 'extranet_clean.books';
+
+ public function handle()
+ {
+ /** @var FluidbookPublication $source */
+ $source = FluidbookPublication::find($this->argument('id'));
+ $map = WorkshopMigration::mapNames(true);
+ $mapValues = WorkshopMigration::mapValues(true);
+
+ $data = [];
+ foreach ($source->getAttributes() as $k => $v) {
+ if ($k === 'settings' || $k === 'id' || !isset($map[$k])) {
+ continue;
+ }
+ $key = isset($map[$k]) ? $map[$k] : $k;
+
+ if (stristr($key, 'date')) {
+ $date = new \DateTime($v);
+ $v = $date->getTimestamp();
+ }
+ $data[$key] = $v;
+
+ }
+ $targetid = $this->argument('targetid');
+ if ($targetid === 'new') {
+ $res = DB::select(DB::raw('SELECT MAX(book_id)+1 AS book_id FROM ' . self::$_wstable));
+ $data['book_id'] = $res[0]->book_id;
+
+ DB::table(self::$_wstable)->insert($data);
+ } else {
+ DB::table(self::$_wstable)->where('book_id', $targetid)->update($data);
+ }
+
+ //DB::table(self::$_wstable)->in
+ }
+}
return json_encode($this->_unserialize($s, $default));
}
- protected function importPublications($reset = false)
+ public static function mapNames($flip = false)
{
- if ($this->option('publications') === 'none') {
- return;
- }
-
- PHP::neverStop();
-
-
- $map = ['book_id' => 'id',
+ $res = ['book_id' => 'id',
'nom' => 'name',
'proprietaire' => 'owner',
'date' => 'created_at',
'composition_update' => 'composition_updated_at',
'exportdatas' => 'export_data',
];
+ if ($flip) {
+ $res = array_flip($res);
+ }
+ return $res;
+ }
+
+ public static function mapValues($flip = false)
+ {
+ $res = ['Open Sans (police du Fluidbook)' => 'OpenSans'];
+ if ($flip) {
+ $res = array_flip($res);
+ }
+ return $res;
+ }
+
+ protected function importPublications($reset = false)
+ {
+ if ($this->option('publications') === 'none') {
+ return;
+ }
+
+ PHP::neverStop();
+
- $mapValues = ['Open Sans (police du Fluidbook)' => 'OpenSans'];
+ $map = self::mapNames();
+ $mapValues = self::mapValues();
$ignore = [];
$c->setAttribute('composition', $composition);
try {
- $c->saveWithoutFlushingCache();
+ $c->saveQuietlyWithoutFlushingCache();
} catch (\Exception $e) {
dd($e);
}