use App\Models\FluidbookDocument;
use App\Models\User;
use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Log;
class FluidbookDocumentUpload extends Base
{
try {
FluidbookDocumentUpload::updateProgression($this->uploadID, $this->document->id, __('Début du traitement du document'), 1.25);
$this->document->processUpload($this->uploadID, $sync);
- Links::addLinksFromPDF($this->fluidbook_id);
} catch (\Throwable $e) {
- error_log($e);
+ Log::error($e);
FluidbookDocumentUpload::updateProgression($this->uploadID, $this->document->id, __('Une erreur s\'est produite :error', ['error' => $e->getMessage()]), -1);
}
}
protected $_documentsSize = null;
+ protected $_compositionUpdated = false;
+
use PublicationSettings;
use SCORMVersionTrait;
}
+ protected function _normalizeComposition($c)
+ {
+ if (is_string($c)) {
+ $c = json_decode($c, true);
+ }
+ $c = ArrayUtil::asArray($c);
+
+ $res = [];
+ foreach ($c as $k => $item) {
+ if (null === $item) {
+ return [];
+ }
+ $res[intval($k)] = [intval($item[0]), intval($item[1])];
+ }
+ ksort($res);
+ return $res;
+ }
+
+ public function setAttribute($key, $value)
+ {
+ if ($key === 'composition') {
+ $value = $this->_normalizeComposition($value);
+ if ($this->_normalizeComposition($this->getAttribute($key)) !== $value) {
+ $this->_compositionUpdated = true;
+ }
+ $this->composition = $value;
+ }
+ return parent::setAttribute($key, $value);
+ }
+
+
public function onSaving(): bool
{
$this->setComposedAttributes();
$this->checkHash();
$this->checkExternalServers();
+ if ($this->_compositionUpdated) {
+ $this->setAttribute('composition_updated_at', new Datetime());
+ }
return parent::onSaving();
}
{
$this->setComposedAttributes();
$this->checkHash();
- FluidbookImagesPreprocess::dispatch($this->id);
+ if ($this->_compositionUpdated) {
+ Links::addLinksFromPDF($this->id);
+ FluidbookImagesPreprocess::dispatch($this->id);
+ }
return parent::onSaved();
}