}
$theme->setAttribute($k, $v);
}
-
-
return $theme;
}
$cl->setArg(null, resource_path('js/social_screenshot/social_screenshot.js'));
$cl->setArg('width', 1024);
$cl->setArg('height', 768);
- $cl->setArg('delay', 2);
+ $cl->setArg('delay', 4);
$cl->setArg('scale', 1);
$cl->setArg('dest', $dest);
$cl->setArg('url', $this->theme->getPreviewURL(['shortLoading'=>1]));
--- /dev/null
+<?php
+
+
+namespace App\Jobs;
+
+
+use App\Models\FluidbookTheme;
+use Cubist\Backpack\Magic\Fields\Color;
+use Cubist\Backpack\Magic\Fields\Files;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Support\Facades\DB;
+use Spatie\MediaLibrary\MediaCollections\Models\Media;
+
+class UpdateWS2ThemeTable implements ShouldQueue
+{
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+ protected static $_colorToWS2Cache = [];
+ protected static $_colorAlphaToWS2Cache = [];
+
+ public function __construct()
+ {
+ }
+
+ public function uniqueId()
+ {
+ return 'updatews2themetable';
+ }
+
+ /**
+ * Execute the job.
+ *
+ * @return void
+ */
+ public function handle()
+ {
+ $theme = new FluidbookTheme();
+
+ $fileFields = [];
+ $colorFields = [];
+ $colorAlphaFields = [];
+ $allFields = [];
+ foreach ($theme->getFields() as $field) {
+ $name = $field->getAttribute('name');
+ $allFields[] = $name;
+ if ($field instanceof Files) {
+ $fileFields[] = $name;
+ } else if ($field instanceof Color) {
+ if ($field->getAttribute('allows_alpha')) {
+ $colorAlphaFields[] = $name;
+ } else {
+ $colorFields[] = $name;
+ }
+ }
+ }
+ $ignore = ['id', 'name', 'owner', 'created_at', 'deleted_at', 'updated_at', 'slug'];
+ $t3dir = '/data1/extranet/www/fluidbook/themes3/';
+
+ $data = [];
+ foreach (FluidbookTheme::all() as $theme) {
+ $settings = [];
+ foreach ($allFields as $k) {
+ if (in_array($k, $ignore)) {
+ continue;
+ }
+ $v = $theme->$k;
+
+ if (in_array($k, $colorAlphaFields)) {
+ $v = self::colorAlphaToWS2($v);
+ } else if (in_array($k, $colorFields)) {
+ $v = self::colorToWS2($v);
+ } else if (in_array($k, $fileFields)) {
+ if (null === $v) {
+ $v = '';
+ } else {
+ /** @var Media $media */
+ $media = $theme->getMedia($v)->get(0);
+ if (null !== $media) {
+ $v = $media->getAttribute('file_name');
+ $dir = $t3dir . $theme->id;
+ if (!file_exists($dir)) {
+ mkdir($dir, 0777, true);
+ }
+ $dest = $dir . '/' . $v;
+ $path = $media->getPath();
+ $exists = file_exists($dest);
+ if (!$exists || realpath($dest) !== realpath($path)) {
+ if ($exists) {
+ unlink($dest);
+ }
+ `ln -s $path $dest`;
+ }
+ } else {
+ $v = '';
+ }
+ }
+ }
+ if (null === $v) {
+ continue;
+ }
+ $settings[$k] = $v;
+ }
+ $data[] = ['theme_id' => $theme->id, 'signature' => 0, 'nom' => $theme->name, 'proprietaire' => $theme->owner, 'icones' => $theme->iconSet, 'date' => strtotime($theme->creation_date), 'parametres' => json_encode($settings)];
+
+ $dest = $t3dir . '/' . $theme->id . '.jpg';
+ if (!file_exists($dest)) {
+ $preview = storage_path('themes/' . $theme->id . '.jpg');
+ `ln -sf $preview $dest`;
+ }
+ }
+ $t = DB::table('extranet_clean.ws3_theme');
+ $t->truncate();
+ $t->insert($data);
+
+ }
+
+ public static function colorAlphaToWS2($data)
+ {
+ if ($data === '') {
+ return null;
+ }
+ if (!isset(self::$_colorAlphaToWS2Cache[$data])) {
+ self::$_colorAlphaToWS2Cache[$data] = self::_colorToWS2($data, true);
+ }
+ return self::$_colorAlphaToWS2Cache[$data];
+ }
+
+ public static function colorToWS2($data)
+ {
+ if ($data === '') {
+ return '';
+ }
+ if (!isset(self::$_colorToWS2Cache[$data])) {
+ self::$_colorToWS2Cache[$data] = self::_colorToWS2($data, false);
+ }
+ return self::$_colorToWS2Cache[$data];
+ }
+
+ protected static function _colorToWS2($data, $alpha): string
+ {
+ $data = trim($data, '# ');
+ if (strlen($data) === 6) {
+ $res = $data;
+ } else if ($data === 'transparent') {
+ $res = '00000000';
+ } else if (preg_match('/rgba?\((\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(\s*,\s*([0-9.]*))?\)/', $data, $matches)) {
+ $res = self::dechex($matches[1]) . self::dechex($matches[2]) . self::dechex($matches[3]);
+ if (isset($matches[5])) {
+ $res = self::dechex($matches[5] * 255) . $res;
+ }
+ } else {
+ $res = $data;
+ }
+ if ($alpha && strlen($res) === 6) {
+ $res = 'ff' . $res;
+ }
+ return $res;
+ }
+
+ public static function dechex($e)
+ {
+ if ($e == 0) {
+ $res = '00';
+ } else {
+ $res = dechex(round($e));
+ if (strlen($res) == 1) {
+ $res = '0' . $res;
+ }
+ }
+ return $res;
+ }
+
+}
use App\Fields\User;
use App\Jobs\GenerateThemePreview;
+use App\Jobs\UpdateWS2ThemeTable;
use Cubist\Backpack\Magic\Fields\Color;
use Cubist\Backpack\Magic\Fields\Files;
use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
'singular' => 'theme',
'plural' => 'themes'];
- protected static $_colorToWS2Cache = [];
+
protected static $_colorToWS3Cache = [];
- protected static $_colorAlphaToWS2Cache = [];
+
protected $_oldRoot = '/home/extranet/www/fluidbook/';
protected $_enableTrackNonDefaultValues = true;
$this->addMediaToField($fieldname, $path, true);
}
- public function updateWS2Table()
- {
- $fileFields = [];
- $colorFields = [];
- $colorAlphaFields = [];
- $allFields = [];
- foreach ($this->getFields() as $field) {
- $name = $field->getAttribute('name');
- $allFields[] = $name;
- if ($field instanceof Files) {
- $fileFields[] = $name;
- } else if ($field instanceof Color) {
- if ($field->getAttribute('allows_alpha')) {
- $colorAlphaFields[] = $name;
- } else {
- $colorFields[] = $name;
- }
- }
- }
- $ignore = ['id', 'name', 'owner', 'created_at', 'deleted_at', 'updated_at', 'slug'];
- $t3dir = '/data1/extranet/www/fluidbook/themes3/';
-
- $data = [];
- foreach (FluidbookTheme::all() as $theme) {
- $settings = [];
- foreach ($allFields as $k) {
- if (in_array($k, $ignore)) {
- continue;
- }
- $v = $theme->$k;
-
- if (in_array($k, $colorAlphaFields)) {
- $v = self::_colorAlphaToWS2($v);
- } else if (in_array($k, $colorFields)) {
- $v = self::_colorToWS2($v);
- } else if (in_array($k, $fileFields)) {
- if (null === $v) {
- $v = '';
- } else {
- /** @var Media $media */
- $media = $theme->getMedia($v)->get(0);
- if (null !== $media) {
- $v = $media->getAttribute('file_name');
- $dir = $t3dir . $theme->id;
- if (!file_exists($dir)) {
- mkdir($dir, 0777, true);
- }
- $dest = $dir . '/' . $v;
- $path = $media->getPath();
- $exists = file_exists($dest);
- if (!$exists || realpath($dest) !== realpath($path)) {
- if ($exists) {
- unlink($dest);
- }
- `ln -s $path $dest`;
- }
- }
- }
- }
- if (null === $v) {
- continue;
- }
- $settings[$k] = $v;
- }
- $data[] = ['theme_id' => $theme->id, 'signature' => 0, 'nom' => $theme->name, 'proprietaire' => $theme->owner, 'icones' => $theme->iconSet, 'date' => strtotime($theme->creation_date), 'parametres' => json_encode($settings)];
-
- $dest = $t3dir . '/' . $theme->id . '.jpg';
- if (!file_exists($dest)) {
- $preview = storage_path('themes/' . $theme->id . '.jpg');
- `ln -s $preview $dest`;
- }
- }
- $t = DB::table('extranet_clean.ws3_theme');
- $t->truncate();
- $t->insert($data);
- }
public static function _colorToWS3($data)
{
return self::$_colorToWS3Cache[$data];
}
- public static function _colorAlphaToWS2($data)
- {
- if ($data === '') {
- return null;
- }
- if (!isset(self::$_colorAlphaToWS2Cache[$data])) {
- self::$_colorAlphaToWS2Cache[$data] = self::__colorToWS2($data, true);
- }
- return self::$_colorAlphaToWS2Cache[$data];
- }
-
- public static function _colorToWS2($data)
- {
- if ($data === '') {
- return '';
- }
- if (!isset(self::$_colorToWS2Cache[$data])) {
- self::$_colorToWS2Cache[$data] = self::__colorToWS2($data, false);
- }
- return self::$_colorToWS2Cache[$data];
- }
-
- protected static function __colorToWS2($data, $alpha)
- {
- $data = trim($data, '# ');
- if (strlen($data) === 6) {
- $res = $data;
- } else if ($data === 'transparent') {
- $res = '00000000';
- } else if (preg_match('/rgba?\((\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(\s*,\s*([0-9.]*))?\)/', $data, $matches)) {
- $res = self::dechex($matches[1]) . self::dechex($matches[2]) . self::dechex($matches[3]);
- if (isset($matches[5])) {
- $res = self::dechex($matches[5] * 255) . $res;
- }
- } else {
- $res = $data;
- }
- if ($alpha && strlen($res) === 6) {
- $res = 'ff' . $res;
- }
- return $res;
- }
-
- public static function dechex($e)
- {
- if ($e == 0) {
- $res = '00';
- } else {
- $res = dechex(round($e));
- if (strlen($res) == 1) {
- $res = '0' . $res;
- }
- }
- return $res;
- }
-
-
public function postSave()
{
parent::postSave();
- if (self::$updateWS2ViewOnChange) {
- $this->updateWS2Table();
- }
+ self::updateWS2Table();
dispatch(new GenerateThemePreview($this))->onQueue('theme');
}
public function postDelete()
{
parent::postDelete();
+ self::updateWS2Table();
+ }
+
+ public static function updateWS2Table()
+ {
if (self::$updateWS2ViewOnChange) {
- $this->updateWS2Table();
+ dispatch(new UpdateWS2ThemeTable())->onConnection('sync');
}
}