vendor/pimcore/pimcore/models/Tool/TmpStore/Dao.php line 51

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\Tool\TmpStore;
  15. use Pimcore\Db\Helper;
  16. use Pimcore\Model;
  17. /**
  18.  * @internal
  19.  *
  20.  * @property \Pimcore\Model\Tool\TmpStore $model
  21.  */
  22. class Dao extends Model\Dao\AbstractDao
  23. {
  24.     /**
  25.      * @param string $id
  26.      * @param mixed $data
  27.      * @param string $tag
  28.      * @param int $lifetime
  29.      *
  30.      * @return bool
  31.      */
  32.     public function add($id$data$tag$lifetime)
  33.     {
  34.         try {
  35.             $serialized false;
  36.             if (is_object($data) || is_array($data)) {
  37.                 $serialized true;
  38.                 $data serialize($data);
  39.             }
  40.             Helper::insertOrUpdate($this->db'tmp_store', [
  41.                 'id' => $id,
  42.                 'data' => $data,
  43.                 'tag' => $tag,
  44.                 'date' => time(),
  45.                 'expiryDate' => (time() + $lifetime),
  46.                 'serialized' => (int) $serialized,
  47.             ]);
  48.             return true;
  49.         } catch (\Exception $e) {
  50.             return false;
  51.         }
  52.     }
  53.     /**
  54.      * @param string $id
  55.      */
  56.     public function delete($id)
  57.     {
  58.         $this->db->delete('tmp_store', ['id' => $id]);
  59.     }
  60.     /**
  61.      * @param string $id
  62.      *
  63.      * @return bool
  64.      */
  65.     public function getById($id)
  66.     {
  67.         $item $this->db->fetchAssociative('SELECT * FROM tmp_store WHERE id = ?', [$id]);
  68.         if (is_array($item) && array_key_exists('id'$item)) {
  69.             if ($item['serialized']) {
  70.                 $item['data'] = unserialize($item['data']);
  71.             }
  72.             $this->assignVariablesToModel($item);
  73.             return true;
  74.         }
  75.         return false;
  76.     }
  77.     /**
  78.      * @param string $tag
  79.      *
  80.      * @return array
  81.      */
  82.     public function getIdsByTag($tag)
  83.     {
  84.         $items $this->db->fetchFirstColumn('SELECT id FROM tmp_store WHERE tag = ?', [$tag]);
  85.         return $items;
  86.     }
  87. }