vendor/pimcore/pimcore/models/Asset/Video/Thumbnail/Config/Dao.php line 35

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Model\Asset\Video\Thumbnail\Config;
  15. use Pimcore\Config\LocationAwareConfigRepository;
  16. use Pimcore\Messenger\CleanupThumbnailsMessage;
  17. use Pimcore\Model;
  18. /**
  19.  * @internal
  20.  *
  21.  * @property \Pimcore\Model\Asset\Video\Thumbnail\Config $model
  22.  */
  23. class Dao extends Model\Dao\PimcoreLocationAwareConfigDao
  24. {
  25.     private const CONFIG_KEY 'video_thumbnails';
  26.     public function configure()
  27.     {
  28.         $config \Pimcore::getContainer()->getParameter('pimcore.config');
  29.         $storageConfig LocationAwareConfigRepository::getStorageConfigurationCompatibilityLayer(
  30.             $config,
  31.             self::CONFIG_KEY,
  32.             'PIMCORE_CONFIG_STORAGE_DIR_VIDEO_THUMBNAILS',
  33.             'PIMCORE_WRITE_TARGET_VIDEO_THUMBNAILS'
  34.         );
  35.         parent::configure([
  36.             'containerConfig' => $config['assets']['video']['thumbnails']['definitions'],
  37.             'settingsStoreScope' => 'pimcore_video_thumbnails',
  38.             'storageDirectory' => $storageConfig,
  39.             'legacyConfigFile' => 'video-thumbnails.php',
  40.         ]);
  41.     }
  42.     /**
  43.      * @param string|null $id
  44.      *
  45.      * @throws \Exception
  46.      */
  47.     public function getByName($id null)
  48.     {
  49.         if ($id != null) {
  50.             $this->model->setName($id);
  51.         }
  52.         $data $this->getDataByName($this->model->getName());
  53.         if ($data && $id != null) {
  54.             $data['id'] = $id;
  55.         }
  56.         if ($data) {
  57.             $this->assignVariablesToModel($data);
  58.             $this->model->setName($data['id']);
  59.         } else {
  60.             throw new Model\Exception\NotFoundException(sprintf(
  61.                 'Thumbnail with ID "%s" does not exist.',
  62.                 $this->model->getName()
  63.             ));
  64.         }
  65.     }
  66.     /**
  67.      * @throws \Exception
  68.      */
  69.     public function save()
  70.     {
  71.         $ts time();
  72.         if (!$this->model->getCreationDate()) {
  73.             $this->model->setCreationDate($ts);
  74.         }
  75.         $this->model->setModificationDate($ts);
  76.         $dataRaw $this->model->getObjectVars();
  77.         $data = [];
  78.         $allowedProperties = ['name''description''group''items''medias',
  79.             'videoBitrate''audioBitrate''creationDate''modificationDate', ];
  80.         foreach ($dataRaw as $key => $value) {
  81.             if (in_array($key$allowedProperties)) {
  82.                 $data[$key] = $value;
  83.             }
  84.         }
  85.         $this->saveData($this->model->getName(), $data);
  86.         $this->autoClearTempFiles();
  87.     }
  88.     /**
  89.      * Deletes object from database
  90.      */
  91.     public function delete()
  92.     {
  93.         $this->deleteData($this->model->getName());
  94.         $this->autoClearTempFiles();
  95.     }
  96.     protected function autoClearTempFiles()
  97.     {
  98.         $enabled \Pimcore::getContainer()->getParameter('pimcore.config')['assets']['video']['thumbnails']['auto_clear_temp_files'];
  99.         if ($enabled) {
  100.             \Pimcore::getContainer()->get('messenger.bus.pimcore-core')->dispatch(
  101.                 new CleanupThumbnailsMessage('video'$this->model->getName())
  102.             );
  103.         }
  104.     }
  105.     /**
  106.      * {@inheritdoc}
  107.      */
  108.     protected function prepareDataStructureForYaml(string $id$data)
  109.     {
  110.         return [
  111.             'pimcore' => [
  112.                 'assets' => [
  113.                     'video' => [
  114.                         'thumbnails' => [
  115.                             'definitions' => [
  116.                                 $id => $data,
  117.                             ],
  118.                         ],
  119.                     ],
  120.                 ],
  121.             ],
  122.         ];
  123.     }
  124. }