public function unite(Identifiable $object, Identifiable $old)
 {
     Assert::isNotNull($object->getId());
     Assert::isTypelessEqual($object->getId(), $old->getId(), 'cannot merge different objects');
     $query = OSQL::update($this->getTable());
     foreach ($this->getProtoClass()->getPropertyList() as $property) {
         $getter = $property->getGetter();
         if ($property->getClassName() === null) {
             $changed = $old->{$getter}() !== $object->{$getter}();
         } else {
             /**
              * way to skip pointless update and hack for recursive
              * comparsion.
              **/
             $changed = $old->{$getter}() !== $object->{$getter}() || $old->{$getter}() != $object->{$getter}();
         }
         if ($changed) {
             $property->fillQuery($query, $object);
         }
     }
     if (!$query->getFieldsCount()) {
         return $object;
     }
     $this->targetizeUpdateQuery($query, $object);
     return $this->doInject($query, $object);
 }
 /**
  * @return AbstractProtoClass
  **/
 public function skipObjectPrefetching(Identifiable $object)
 {
     if ($this->depth) {
         if (!isset($this->skipList[$this->depth][$object->getId()])) {
             $this->skipList[$this->depth][$object->getId()] = 1;
         } else {
             ++$this->skipList[$this->depth][$object->getId()];
         }
     }
     return $this;
 }
 protected function update()
 {
     $user = User::getUserById($this->id);
     if ($user->pass != $this->pass) {
         $this->encodePassword();
     }
     parent::update();
 }
 public function delete()
 {
     $context = Context::getInstance();
     $role = $this->checkAccess($context->user);
     if ($role <= Acl::READER) {
         throw new PermissionDenied("No permission to delete");
     }
     parent::delete();
 }
 public function merge(Identifiable $object, $cacheOnly = true)
 {
     Assert::isNotNull($object->getId());
     $this->checkObjectType($object);
     $old = Cache::worker($this)->getCachedById($object->getId());
     if (!$old) {
         // unlikely
         if ($cacheOnly) {
             return $this->save($object);
         } else {
             $old = Cache::worker($this)->getById($object->getId());
         }
     }
     if ($object === $old) {
         return $this->save($object);
     }
     return $this->unite($object, $old);
 }
 public static function getAllLanguages()
 {
     if (is_null(Language::$langs)) {
         $context = Context::getInstance();
         $oLang = Language::getLanguageById($context->session->lang);
         $order = sprintf("(CASE WHEN id=%d THEN 0 ELSE 1 END)", $oLang->id);
         $rs = Identifiable::getAllItemsByTable(new Language(), $order);
         Language::$langs = new ObjectSet($rs, __CLASS__);
     }
     return Language::$langs;
 }
 public function on_update()
 {
     parent::on_update();
     $db = DB::getInstance();
     $oRef = new ReflectionClass($this->getSpiderClassName());
     $oSpider = $oRef->newInstance(array());
     $table = $oSpider->table['table'];
     $rs = Identifiable::getItemById($this->spiderID, $table);
     $oSpider = $oRef->newInstance($rs);
     $oSpider->description = strip_tags($this->description);
     $oSpider->name = $this->name;
     $oSpider->save();
 }
Exemple #8
0
 public function unserialize($data)
 {
     parent::unserialize($data);
     $this->initPermissions();
 }
 /**
  * Update object to DB
  * Walk through the object's attrs
  * and escape them
  *
  * @return bool
  */
 protected function update()
 {
     $pk = $this->getPkValues();
     $data = $this->getAttrs();
     foreach ($this->table['PK'] as $key => $val) {
         unset($data[$key]);
     }
     try {
         array_walk($data, array($this, 'escape'));
     } catch (InvalidValue $e) {
         throw new AppException($e->getMessage());
     }
     $k = array_keys($data);
     $v = array_values($data);
     $c = join(",", array_map(array($this, 'joinAll'), $k, $v));
     $q = "UPDATE {$this->table['table']} SET {$c} WHERE {$pk}";
     $db = DB::getInstance();
     $old = Identifiable::getItemById($this->id, $this);
     if (!$db->db_query($q)) {
         if ($db->db_errno() == 1062) {
             throw new DuplicateEntry($db->db_error());
         } else {
             throw new AppException("Error updating object. Query [{$q}] {$db->db_error()}", true);
         }
     }
     $this->on_update($old);
 }
 /**
  * @return BinaryExpression
  **/
 public static function eqId($field, Identifiable $object)
 {
     return self::eq($field, DBValue::create($object->getId()));
 }
 private function addObjectToMap(Identifiable $object)
 {
     return $this->identityMap[$object->getId()] = $object;
 }
 public static function getGroupById($id)
 {
     return parent::getItemById($id, new Group());
 }
 public function drop(Identifiable $object)
 {
     return $this->dropById($object->getId());
 }
 public function __construct(array $data = array())
 {
     parent::__construct($data);
 }
Exemple #15
0
 /**
  * @param Identifiable $other
  *
  * @return bool
  */
 public function isSameAs(Identifiable $other) : bool
 {
     return $this->getId() == $other->getId();
 }