{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+ protected $id = 'all';
+
+ protected $_fileFields = [];
+ protected $_colorFields = [];
+ protected $_colorAlphaFields = [];
+ protected $_allFields = [];
+ protected $_ignore = [];
+ protected $_t3dir = '/data1/extranet/www/fluidbook/themes3/';
+
protected static $_colorToWS2Cache = [];
protected static $_colorAlphaToWS2Cache = [];
- public function __construct()
+ public function __construct($id = 'all')
{
+ $this->id = $id;
}
public function uniqueId()
{
- return 'updatews2themetable';
+ return 'updatews2themetable_' . $this->id;
}
/**
{
$theme = new FluidbookTheme();
- $fileFields = [];
- $colorFields = [];
- $colorAlphaFields = [];
- $allFields = [];
foreach ($theme->getFields() as $field) {
$name = $field->getAttribute('name');
- $allFields[] = $name;
+ $this->_allFields[] = $name;
if ($field instanceof Files) {
- $fileFields[] = $name;
+ $this->_fileFields[] = $name;
} else if ($field instanceof Color) {
if ($field->getAttribute('allows_alpha')) {
- $colorAlphaFields[] = $name;
+ $this->_colorAlphaFields[] = $name;
} else {
- $colorFields[] = $name;
+ $this->_colorFields[] = $name;
}
}
}
- $ignore = ['id', 'name', 'owner', 'created_at', 'deleted_at', 'updated_at', 'slug'];
- $t3dir = '/data1/extranet/www/fluidbook/themes3/';
+ $this->_ignore = ['id', 'name', 'owner', 'created_at', 'deleted_at', 'updated_at', 'slug'];
$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 = '';
+ $t = DB::table('extranet_clean.ws3_theme');
+ if ($this->id === 'all') {
+ foreach (FluidbookTheme::all() 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->insert($data);
+ }
+
+ protected function _handleTheme($theme)
+ {
+ $res = $this->_getThemeData($theme);
+ $dest = $this->_t3dir . '/' . $theme->id . '.jpg';
+ if (!file_exists($dest)) {
+ $preview = storage_path('themes/' . $theme->id . '.jpg');
+ `ln -sf $preview $dest`;
+ }
+ return $res;
+ }
+
+ protected function _getThemeData($theme)
+ {
+ $settings = [];
+ foreach ($this->_allFields as $k) {
+ if (in_array($k, $this->_ignore)) {
+ continue;
+ }
+ $v = $theme->$k;
+
+ if (in_array($k, $this->_colorAlphaFields)) {
+ $v = self::colorAlphaToWS2($v);
+ } else if (in_array($k, $this->_colorFields)) {
+ $v = self::colorToWS2($v);
+ } else if (in_array($k, $this->_fileFields)) {
+ if (null === $v) {
+ $v = '';
+ } else {
+ /** @var Media $media */
+ $media = $theme->getMedia($v)->get(0);
+ if (null !== $media) {
+ $v = $media->getAttribute('file_name');
+ $dir = $this->_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)) {
+ `rm -f $dest;ln -sf $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`;
+ if (null === $v) {
+ continue;
}
+ $settings[$k] = $v;
}
- $t = DB::table('extranet_clean.ws3_theme');
- $t->truncate();
- $t->insert($data);
-
+ return ['theme_id' => $theme->id, 'signature' => 0, 'nom' => $theme->name, 'proprietaire' => $theme->owner, 'icones' => $theme->iconSet, 'date' => strtotime($theme->creation_date), 'parametres' => json_encode($settings)];
}
public static function colorAlphaToWS2($data)