/** * Default run method for default 'write-typed' controller * * Save data from the posted form into the first parameter object using standard method. * Create a new instance of this object if no identifier was given. * * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @return string * @throws Exception */ public function run(Parameters $parameters, $form, $files, $class_name) { $object = $parameters->getMainObject($class_name); Dao::begin(); try { $builder = new Post_Files(); $form = $builder->appendToForm($form, $files); $builder = new Object_Builder_Array(); $builder->null_if_empty_sub_objects = true; $builder->build($form, $object); $write_objects = []; foreach ($builder->getBuiltObjects() as $write_object) { if ($write_object == $object || Dao::getObjectIdentifier($write_object)) { $write_objects[] = $write_object; } } $write_error = false; foreach ($write_objects as $write_object) { if (!Dao::write($write_object)) { $write_error = true; break; } } $write_error ? Dao::rollback() : Dao::commit(); } catch (Exception $exception) { Dao::rollback(); throw $exception; } $parameters = $this->getViewParameters($parameters, $class_name, $write_error); return View::run($parameters, $form, $files, $class_name, Feature::F_WRITE); }
/** * Load a counter linked to the class of an object from default data link and increment it * * @param $object object The object to use to format the counter * @param $identifier string The identifier of the counter ; default is get_class($object) * @return string The new counter value */ public static function increment($object, $identifier = null) { Dao::begin(); if (empty($identifier)) { $identifier = Builder::current()->sourceClassName(get_class($object)); } $counter = Dao::searchOne(['identifier' => $identifier], get_called_class()) ?: new Counter($identifier); $next_value = $counter->next($object); Dao::write($counter); Dao::commit(); return $next_value; }
/** * @param $object Framework\Logger */ public function onLoggerStop(Framework\Logger $object) { if ($this->log_flag) { Dao::begin(); foreach (Dao::search(['log' => Func::isNull()], Compiler_Log::class) as $logger) { /** @var $logger Compiler_Log */ $logger->log = $object->log_entry; Dao::write($logger, [Dao::only(['log'])]); } $this->log_flag = false; Dao::commit(); } }
/** * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @return mixed */ public function run(Parameters $parameters, $form, $files, $class_name) { $replaced = $parameters->getMainObject(); $objects = $parameters->getObjects(); if ($id_replace_with = $parameters->getRawParameter('id_replace_with')) { $objects['replace_with'] = $replacement = Dao::read($id_replace_with, $class_name); Dao::begin(); if ((new Delete_And_Replace())->deleteAndReplace($replaced, $replacement)) { Dao::commit(); $objects['done'] = true; } else { Dao::rollback(); $objects['error'] = true; } } return View::run($objects, $form, $files, $class_name, 'deleteAndReplace'); }
/** * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @return mixed */ public function run(Parameters $parameters, $form, $files, $class_name) { $parameters = $parameters->getObjects(); Dao::begin(); $deleted = 0; foreach ($parameters as $object) { if (is_object($object)) { if (!Dao::delete($object)) { $deleted = 0; break; } $deleted++; } } Dao::commit(); $parameters['deleted'] = $deleted ? true : false; return View::run($parameters, $form, $files, $class_name, Feature::F_DELETE); }
/** * @param $last_time integer compile only files modified since this time */ public function compile($last_time = 0) { set_time_limit(900); clearstatcache(); $cache_dir = $this->getCacheDir(); // create data set for dependencies, check for dependencies for deleted files Dao::createStorage(Dependency::class); Dao::begin(); if (isset($_GET['Z'])) { $link = Dao::current(); if ($link instanceof Link) { $link->query('TRUNCATE TABLE `dependencies`'); } } foreach (Dao::select(Dependency::class, ['file_name' => Func::distinct()]) as $file_dependency) { /** @var $file_dependency List_Row */ $file_name = $file_dependency->getValue('file_name'); if (!file_exists($file_name)) { foreach (Dao::search(['file_name' => $file_name], Dependency::class) as $dependency) { /** @var $dependency Dependency */ Dao::delete($dependency); foreach (Dao::search(['dependency_name' => $dependency->class_name], Dependency::class) as $sub_dependency) { /** @var $sub_dependency Dependency */ Dao::delete($sub_dependency); } } } } Dao::commit(); $this->sources = array_merge($this->more_sources, $this->getFilesToCompile($last_time)); $first_group = true; foreach ($this->compilers as $compilers) { /** @var $compilers ICompiler[] */ $saved_sources = $this->sources; while ($this->sources) { // get source and update dependencies foreach ($this->sources as $source) { /** @var Reflection_Source $source inspector bug */ /** @noinspection PhpParamsInspection inspector bug (a Dependency is an object) */ (new Set())->replace($source->getDependencies(true), Dependency::class, ['file_name' => $source->file_name]); } do { $added = []; // ask each compiler for adding of compiled files, until they have nothing to add foreach ($compilers as $compiler) { if ($compiler instanceof Needs_Main) { $compiler->setMainController($this->main_controller); } $added = array_merge($added, $compiler->moreSourcesToCompile($this->sources)); } foreach ($added as $source) { /** @var Reflection_Source $source inspector bug */ /** @noinspection PhpParamsInspection inspector bug (a Dependency is an object) */ (new Set())->replace($source->getDependencies(true), Dependency::class, ['file_name' => $source->file_name]); $this->sources[$source->file_name] = $source; } if (count($compilers) == 1) { $added = []; } } while ($added); $saved_sources = array_merge($saved_sources, $this->sources); // fill in sources cache $sources_count = count($this->sources); foreach ($this->sources as $source) { foreach (array_keys($source->getClasses()) as $class_name) { $this->sources_cache[$class_name] = $source; } if ($sources_count > self::MAX_OPENED_SOURCES) { $source->free(self::SOURCES_FREE); } } // compile sources foreach ($this->sources as $source) { $this->compileSource($source, $compilers, $cache_dir, $first_group, $sources_count); } $this->sources = $this->more_sources; $this->more_sources = []; foreach ($this->sources as $source) { if (!isset($saved_sources[$source->file_name])) { $saved_sources[$source->file_name] = $source; } } } $this->sources = $saved_sources; $first_group = false; } $this->sources = null; }
/** * Imports a data array using settings * * $array is a reference to avoid array replication. * Beware : if $array begins with a 'Class_Name' row, this first row will be removed ! * Beware : first row must contain property paths, and will be removed ! * * @param $array array $value = string[$row_number][$column_number] */ public function importArray(&$array) { Dao::begin(); $class_name = self::getClassNameFromArray($array) ?: $this->class_name; if (isset($class_name)) { $this->class_name = $class_name; } list($this->properties_link, $this->properties_column) = self::getPropertiesLinkAndColumn($this->class_name, self::getPropertiesFromArray($array, $this->class_name)); $key = key($array); foreach ($this->sortedClasses() as $class) { reset($array); while (key($array) !== $key) { next($array); } $this->importArrayClass($class, $array); } if ($this->simulation) { Dao::rollback(); } else { Dao::commit(); } }