Пример #1
0
 public static function down(DAOConnected $object, LogicalObject $exp = null)
 {
     $getMethod = 'get' . ucfirst(self::$property);
     Assert::isTrue(method_exists($object, $getMethod));
     $oldPosition = $object->{$getMethod}();
     $criteria = Criteria::create($object->dao())->add(Expression::gt(self::$property, $oldPosition))->addOrder(OrderBy::create(self::$property)->asc())->setLimit(1);
     if ($exp) {
         $criteria->add($exp);
     }
     if ($lowerObject = $criteria->get()) {
         DaoUtils::setNullValue(self::$nullValue);
         DaoUtils::swap($lowerObject, $object, self::$property);
     }
 }
Пример #2
0
 private function loadNextChunk($id)
 {
     Assert::isNotNull($this->dao);
     $this->offset = 0;
     $criteria = Criteria::create($this->dao);
     if ($this->projection) {
         $criteria->setProjection($this->projection);
     }
     $criteria->addOrder($this->keyProperty)->setLimit($this->chunkSize);
     if ($id !== null) {
         $criteria->add(Expression::gt($this->keyProperty, $id));
     }
     // preserving memory bloat
     $this->dao->dropIdentityMap();
     $this->chunk = $criteria->getList();
     return $this->chunk;
 }
Пример #3
0
 /**
  * @return MetaConfiguration
  **/
 public function checkIntegrity()
 {
     $out = $this->getOutput()->newLine()->infoLine('Checking sanity of generated files: ')->newLine();
     $out->info("\t");
     $formErrors = [];
     foreach ($this->classes as $name => $class) {
         if (!($class->getPattern() instanceof SpookedClassPattern || $class->getPattern() instanceof SpookedEnumerationPattern || $class->getPattern() instanceof SpookedEnumPattern || $class->getPattern() instanceof SpookedRegistryPattern || $class->getPattern() instanceof InternalClassPattern) && class_exists(MetaClassNameBuilder::getClassOfMetaClass($class, true))) {
             $out->info($name, true);
             $className = MetaClassNameBuilder::getClassOfMetaClass($class);
             $info = new \ReflectionClass($className);
             $this->checkClassSanity($class, $info);
             if ($info->implementsInterface(Prototyped::class)) {
                 $this->checkClassSanity($class, new \ReflectionClass($class->getProtoClass()));
             }
             if ($info->implementsInterface(DAOConnected::class)) {
                 $this->checkClassSanity($class, new \ReflectionClass($class->getDaoClass()));
             }
             foreach ($class->getInterfaces() as $interface) {
                 Assert::isTrue($info->implementsInterface($interface), 'class ' . $class->getName() . ' expected to implement interface ' . $interface);
             }
             // special handling for Enumeration instances
             if ($class->getPattern() instanceof EnumerationClassPattern || $class->getPattern() instanceof EnumClassPattern || $class->getPattern() instanceof RegistryClassPattern) {
                 $object = new $className(call_user_func([$className, 'getAnyId']));
                 Assert::isTrue(unserialize(serialize($object)) == $object);
                 $out->info(', ');
                 if ($this->checkEnumerationRefIntegrity) {
                     if ($object instanceof Enumeration || $object instanceof Enum || $object instanceof Registry) {
                         $this->checkEnumerationReferentialIntegrity($object, $class->getTableName());
                     }
                 }
                 continue;
             }
             if ($class->getPattern() instanceof AbstractClassPattern) {
                 $out->info(', ');
                 continue;
             }
             /** @var Prototyped $object */
             $object = new $className();
             $proto = $object->proto();
             $form = $proto->makeForm();
             foreach ($class->getProperties() as $name => $property) {
                 Assert::isTrue($property->toLightProperty($class) == $proto->getPropertyByName($name), 'defined property does not match autogenerated one - ' . $class->getName() . '::' . $property->getName());
             }
             if (!$object instanceof DAOConnected) {
                 $out->info(', ');
                 continue;
             }
             $dao = $object->dao();
             Assert::isEqual($dao->getIdName(), $class->getIdentifier()->getColumnName(), 'identifier name mismatch in ' . $class->getName() . ' class');
             try {
                 DBPool::getByDao($dao);
             } catch (MissingElementException $e) {
                 // skipping
                 $out->info(', ');
                 continue;
             }
             $query = Criteria::create($dao)->setLimit(1)->add(Expression::notNull($class->getIdentifier()->getName()))->addOrder($class->getIdentifier()->getName())->toSelectQuery();
             $out->warning(' (' . $query->getFieldsCount() . '/' . $query->getTablesCount() . '/');
             $clone = clone $object;
             if (serialize($clone) == serialize($object)) {
                 $out->info('C', true);
             } else {
                 $out->error('C', true);
             }
             $out->warning('/');
             try {
                 $object = $dao->getByQuery($query);
                 $form = $object->proto()->makeForm();
                 FormUtils::object2form($object, $form);
                 if ($errors = $form->getErrors()) {
                     $formErrors[$class->getName()] = $errors;
                     $out->error('F', true);
                 } else {
                     $out->info('F', true);
                 }
             } catch (ObjectNotFoundException $e) {
                 $out->warning('F');
             }
             $out->warning('/');
             if (Criteria::create($dao)->setFetchStrategy(FetchStrategy::cascade())->toSelectQuery() == $dao->makeSelectHead()) {
                 $out->info('H', true);
             } else {
                 $out->error('H', true);
             }
             $out->warning('/');
             // cloning once again
             $clone = clone $object;
             FormUtils::object2form($object, $form);
             FormUtils::form2object($form, $object);
             if ($object != $clone) {
                 $out->error('T', true);
             } else {
                 $out->info('T', true);
             }
             $out->warning(')')->info(', ');
         }
     }
     $out->infoLine('done.');
     if ($formErrors) {
         $out->newLine()->errorLine('Errors found:')->newLine();
         foreach ($formErrors as $class => $errors) {
             $out->errorLine("\t" . $class . ':', true);
             foreach ($errors as $name => $error) {
                 $out->errorLine("\t\t" . $name . ' - ' . ($error == Form::WRONG ? ' wrong' : ' missing'));
             }
             $out->newLine();
         }
     }
     return $this;
 }