vendor/pimcore/pimcore/models/Element/Editlock/Dao.php line 58

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\Element\Editlock;
  15. use Pimcore\Db\Helper;
  16. use Pimcore\Model;
  17. /**
  18.  * @internal
  19.  *
  20.  * @property \Pimcore\Model\Element\Editlock $model
  21.  */
  22. class Dao extends Model\Dao\AbstractDao
  23. {
  24.     /**
  25.      * @param int $cid
  26.      * @param string $ctype
  27.      *
  28.      * @throws Model\Exception\NotFoundException
  29.      */
  30.     public function getByElement($cid$ctype)
  31.     {
  32.         $data $this->db->fetchAssociative('SELECT * FROM edit_lock WHERE cid = ? AND ctype = ?', [$cid$ctype]);
  33.         if (!$data) {
  34.             throw new Model\Exception\NotFoundException('Lock with cid ' $cid ' and ctype ' $ctype ' not found');
  35.         }
  36.         $this->assignVariablesToModel($data);
  37.         // add elements path
  38.         $element Model\Element\Service::getElementById($ctype$cid);
  39.         if ($element) {
  40.             $this->model->setCpath($element->getRealFullPath());
  41.         }
  42.     }
  43.     /**
  44.      * Save object to database
  45.      *
  46.      * @return bool
  47.      *
  48.      * @todo: not all save methods return a boolean, why this one?
  49.      */
  50.     public function save()
  51.     {
  52.         $version $this->model->getObjectVars();
  53.         $data = [];
  54.         foreach ($version as $key => $value) {
  55.             if (in_array($key$this->getValidTableColumns('edit_lock'))) {
  56.                 $data[$key] = $value;
  57.             }
  58.         }
  59.         Helper::insertOrUpdate($this->db'edit_lock'$data);
  60.         $lastInsertId $this->db->lastInsertId();
  61.         if (!$this->model->getId() && $lastInsertId) {
  62.             $this->model->setId((int) $lastInsertId);
  63.         }
  64.         return true;
  65.     }
  66.     /**
  67.      * Deletes object from database
  68.      */
  69.     public function delete()
  70.     {
  71.         $this->db->delete('edit_lock', ['id' => $this->model->getId()]);
  72.     }
  73.     /**
  74.      * @param string $sessionId
  75.      */
  76.     public function clearSession($sessionId)
  77.     {
  78.         $this->db->delete('edit_lock', ['sessionId' => $sessionId]);
  79.     }
  80. }