Example #1
0
 public static function increment(DAOConnected &$object, array $fields, $refreshCurrent = true, $query = null)
 {
     $objectDao = $object->dao();
     if ($query) {
         $updateQuery = $query;
     } else {
         $updateQuery = OSQL::update()->setTable($objectDao->getTable())->where(Expression::eqId('id', $object));
     }
     $mapping = $objectDao->getProtoClass()->getMapping();
     foreach ($mapping as $field => $column) {
         if (isset($fields[$field])) {
             $updateQuery->set($column, Expression::add($column, $fields[$field]));
         }
     }
     $updateCount = DBPool::getByDao($objectDao)->queryCount($updateQuery);
     if ($query) {
         $objectDao->uncacheLists();
     } else {
         $objectDao->uncacheById($object->getId());
     }
     if ($refreshCurrent && !$query) {
         $object = $objectDao->getById($object->getId());
     }
     return $updateCount;
 }
Example #2
0
 public function unite(Identifiable $object, Identifiable $old)
 {
     $query = $this->getProtoClass()->fillQuery(OSQL::update($this->getTable()), $object, $old);
     $this->runTrigger($object, OnBeforeSave::class);
     if (!$query->getFieldsCount()) {
         return $object;
     }
     return $this->doInject($this->targetizeUpdateQuery($query, $object), $object);
 }
Example #3
0
 private function checkEnumerationReferentialIntegrity($enumeration, $tableName)
 {
     Assert::isTrue($enumeration instanceof Enumeration || $enumeration instanceof Enum || $enumeration instanceof Registry, 'argument enumeation must be instacne of Enumeration or Enum! gived, "' . gettype($enumeration) . '"');
     $updateQueries = null;
     $db = DBPool::me()->getLink();
     $class = get_class($enumeration);
     $ids = [];
     if ($enumeration instanceof Enumeration) {
         $list = $enumeration->getList();
     } elseif ($enumeration instanceof Enum) {
         $list = ClassUtils::callStaticMethod($class . '::getList');
     } elseif ($enumeration instanceof Registry) {
         $list = ClassUtils::callStaticMethod($class . '::getList');
     }
     foreach ($list as $enumerationObject) {
         $ids[$enumerationObject->getId()] = $enumerationObject->getName();
     }
     $rows = $db->querySet(OSQL::select()->from($tableName)->multiGet('id', 'name'));
     echo "\n";
     foreach ($rows as $row) {
         if (!isset($ids[$row['id']])) {
             echo "Class '{$class}', strange id: {$row['id']} found. \n";
         } else {
             if ($ids[$row['id']] != $row['name']) {
                 echo "Class '{$class}',id: {$row['id']} sync names. \n";
                 $updateQueries .= OSQL::update($tableName)->set('name', $ids[$row['id']])->where(Expression::eq('id', $row['id']))->toDialectString($db->getDialect()) . ";\n";
             }
             unset($ids[$row['id']]);
         }
     }
     foreach ($ids as $id => $name) {
         echo "Class '{$class}', id: {$id} not present in database. \n";
     }
     echo $updateQueries;
     return $this;
 }
 /**
  * @return UpdateQuery
  **/
 private function makeMassUpdateQuery($ids)
 {
     $uc = $this->container;
     return OSQL::update($uc->getDao()->getTable())->set($uc->getParentIdField(), null)->where(Expression::in($uc->getChildIdField(), $ids));
 }