use Cubist\Util\CommandLine\Imagemagick;
use Cubist\Util\Graphics\Image;
use Fluidbook\Tools\SVG\SVGTools;
+use Illuminate\Database\UniqueConstraintViolationException;
+use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Mockery\Exception;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
*/
public function handle()
{
- $theme = new FluidbookTheme();
-
- foreach ($theme->getFields() as $field) {
- $name = $field->getAttribute('name');
- $this->_allFields[] = $name;
- if ($field instanceof Files) {
- $this->_fileFields[] = $name;
- } else if ($field instanceof Color) {
- if ($field->getAttribute('allows_alpha')) {
- $this->_colorAlphaFields[] = $name;
- } else {
- $this->_colorFields[] = $name;
+ $lock = Cache::lock('job_' . $this->uniqueId(), 10);
+ if ($lock->get()) {
+ $theme = new FluidbookTheme();
+
+ foreach ($theme->getFields() as $field) {
+ $name = $field->getAttribute('name');
+ $this->_allFields[] = $name;
+ if ($field instanceof Files) {
+ $this->_fileFields[] = $name;
+ } else if ($field instanceof Color) {
+ if ($field->getAttribute('allows_alpha')) {
+ $this->_colorAlphaFields[] = $name;
+ } else {
+ $this->_colorFields[] = $name;
+ }
}
}
- }
- $this->_ignore = ['id', 'name', 'owner', 'created_at', 'deleted_at', 'updated_at', 'slug', 'signature'];
+ $this->_ignore = ['id', 'name', 'owner', 'created_at', 'deleted_at', 'updated_at', 'slug', 'signature'];
- $data = [];
- $t = DB::table('extranet_clean.ws3_themes');
- if ($this->id === 'all') {
- foreach (FluidbookTheme::where('created_ok', 1)->get() as $theme) {
+ $data = [];
+ $t = DB::table('extranet_clean.ws3_themes');
+ if ($this->id === 'all') {
+ foreach (FluidbookTheme::where('created_ok', 1)->get() as $theme) {
+ $data[] = $this->_handleTheme($theme);
+ }
+ $t->truncate();
+ } else {
+ $theme = FluidbookTheme::find($this->id);
$data[] = $this->_handleTheme($theme);
+ $t->where('theme_id', '=', $this->id)->delete();
}
- $t->truncate();
- } else {
- $theme = FluidbookTheme::find($this->id);
- $data[] = $this->_handleTheme($theme);
- $t->where('theme_id', '=', $this->id)->delete();
- }
- try {
- $t->insert($data);
- } catch (Exception $e) {
+ try {
+ $t->insert($data);
+ } catch (Exception|UniqueConstraintViolationException $e) {
+ }
+ $lock->release();
}
}
return self::$_colorToWS3Cache[$data];
}
- public function postSave()
+ public function onSaved(): bool
{
- parent::postSave();
+ $res = parent::onSaved();
self::updateWS2Table($this->id);
$this->_generateThemePreview();
+ return $res;
}
protected function _generateThemePreview($sync = false)
dispatch(new GenerateThemePreview($this))->onQueue('theme');
}
- public function postCreate()
- {
- parent::postCreate();
- self::updateWS2Table($this->id);
- $this->_generateThemePreview();
- }
-
- public function postDelete()
+ public function onDeleted(): bool
{
- parent::postDelete();
+ $res = parent::onDeleted();
self::updateWS2Table();
+ return $res;
}
public static function updateWS2Table($id = null)
{
+
if (self::$updateWS2ViewOnChange) {
if (null !== $id) {
- $job = new UpdateWS2ThemeTable($id);
- dispatch_sync($job);
+ dispatch_sync(new UpdateWS2ThemeTable($id));
}
dispatch(new UpdateWS2ThemeTable('all'))->onQueue('theme');
}