public function handle(InputInterface $input, OutputInterface $output) { $availableTags = BaseOrm::getCheckRegistry()->tagsAvailable(); if ($input->getOption('list-tags')) { $output->writeln(implode(PHP_EOL, $availableTags)); return; } $tags = $input->getOption('tag'); if ($tags) { $invalidTags = []; foreach ($tags as $tag) { if (!BaseOrm::getCheckRegistry()->tagExists($tag)) { $invalidTags[] = $tag; } } if ($invalidTags) { throw new CommandError(sprintf('There is no system check with the "%s" tag(s).', implode(', ', $invalidTags))); } } $failLevel = $input->getOption('fail-level'); if ($failLevel) { if (!in_array(strtoupper($failLevel), ['ERROR', 'WARNING', 'INFO', 'DEBUG', 'CRITICAL'])) { throw new CommandError(sprintf("--fail-level: invalid choice: '%s' " . "(choices are 'CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG')", $failLevel)); } } try { $this->check($input, $output, $tags, true, $failLevel); } catch (SystemCheckError $e) { // we get a system check error, stop further processing return; } }
public function getComponentsPath() { $components = (array) BaseOrm::getInstance()->components; $paths = []; foreach ($components as $name => $path) { $paths[$name] = sprintf('%ssrc/Console/Command', $path); } return $paths; }
public function getConstructorArgs() { $constructorArgs = parent::getConstructorArgs(); if (isset($constructorArgs['meta']) && empty($constructorArgs['meta'])) { unset($constructorArgs['meta']); } if (isset($constructorArgs['extends'])) { if (StringHelper::isEmpty($constructorArgs['extends']) || Model::isModelBase($constructorArgs['extends'])) { unset($constructorArgs['extends']); } else { $constructorArgs['extends'] = ClassHelper::getNameFromNs($constructorArgs['extends'], BaseOrm::getModelsNamespace()); } } return $constructorArgs; }
public function handle(InputInterface $input, OutputInterface $output) { $name = $input->getArgument('migration_name'); if ($input->getOption('fake')) { $fake = true; } else { $fake = false; } $connection = BaseOrm::getDbConnection(); $registry = BaseOrm::getRegistry(); $executor = Executor::createObject($connection); // target migrations to act on if (!empty($name)) { if ($name == 'zero') { $targets = [$name]; } else { $targets = $executor->loader->getMigrationByPrefix($name); } } else { $targets = $executor->loader->graph->getLeafNodes(); } // get migration plan $plan = $executor->getMigrationPlan($targets); BaseOrm::signalDispatch('powerorm.migration.pre_migrate', $this); $output->writeln('<comment>Running migrations:</comment>'); if (empty($plan)) { $output->writeln(' No migrations to apply.'); if ($input->getOption('no-interaction')) { $asker = NonInteractiveAsker::createObject($input, $output); } else { $asker = InteractiveAsker::createObject($input, $output); } //detect if we need to make migrations $auto_detector = new AutoDetector($executor->loader->getProjectState(), ProjectState::fromApps($registry), $asker); $changes = $auto_detector->getChanges($executor->loader->graph); if (!empty($changes)) { $output->writeln('<warning> Your models have changes that are not yet reflected ' . "in a migration, and so won't be applied.</warning>"); $output->writeln("<warning> Run 'php pmanager.php makemigrations' to make new " . "migrations, and then re-run 'php pmanager.php migrate' to apply them.</warning>"); } } else { // migrate $executor->migrate($targets, $plan, $fake); } BaseOrm::signalDispatch('powerorm.migration.post_migrate', $this); }
public function _writeMigrations($migrationChanges, InputInterface $input, OutputInterface $output) { $output->writeln('Creating Migrations :'); /** @var $migration Migration */ /* @var $op Operation */ foreach ($migrationChanges as $migration) { $migrationFile = MigrationFile::createObject($migration); $fileName = $migrationFile->getFileName(); $output->writeln(' ' . $fileName); $operations = $migration->getOperations(); foreach ($operations as $op) { $output->writeln(sprintf(' - %s', ucwords($op->getDescription()))); } // write content to file. $handler = new FileHandler(BaseOrm::getMigrationsPath(), $fileName); $handler->write($migrationFile->getContent()); } }
public function handle(InputInterface $input, OutputInterface $output) { $connection = BaseOrm::getDbConnection(); // get migrations list $loader = new Loader($connection, true); $leaves = $loader->graph->getLeafNodes(); foreach ($leaves as $leaf) { $list = $loader->graph->getAncestryTree($leaf); foreach ($list as $item) { $migrationName = array_pop(explode('\\', $item)); if (in_array($item, $loader->appliedMigrations)) { $indicator = '<info>(applied)</info>'; } else { $indicator = '(pending)'; } $output->writeln(sprintf('%1$s %2$s', $indicator, $migrationName)); } } }
public function __construct($params) { BaseOrm::configure($this, $params); }
/** * {@inheritdoc} */ public function getConstructorArgs() { $kwargs = parent::getConstructorArgs(); if (ArrayHelper::hasKey($kwargs, 'onDelete')) { $kwargs['onDelete'] = $this->relation->onDelete; } if (is_string($this->relation->toModel)) { $kwargs['to'] = $this->relation->toModel; } else { $name = $this->relation->toModel->getFullClassName(); $kwargs['to'] = ClassHelper::getNameFromNs($name, BaseOrm::getModelsNamespace()); } if ($this->relation->parentLink) { $kwargs['parentLink'] = $this->relation->parentLink; } return $kwargs; }
/** * Do an INSERT. If update_pk is defined then this method should return the new pk for the model. * * @param Model $model * @param $fields * @param $returnId * * @return mixed * * @since 1.1.0 * * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**> */ private function doInsert(Model $model, $fields, $returnId) { $conn = BaseOrm::getDbConnection(); $qb = $conn->createQueryBuilder(); $qb->insert($model->meta->dbTable); /** @var $field Field */ foreach ($fields as $name => $field) { $qb->setValue($field->getColumnName(), $qb->createNamedParameter($field->preSave($model, true))); } $qb->execute(); if ($returnId) { return $conn->lastInsertId(); } return; }
public function isSilenced() { return in_array($this->id, BaseOrm::getInstance()->silencedChecks); }
public function registerModel(Model $model) { $name = ClassHelper::getNameFromNs($model->meta->modelName, BaseOrm::getModelsNamespace()); if (!ArrayHelper::hasKey($this->allModels, $name)) { $this->allModels[$name] = $model; } $this->resolvePendingOps($model); }
private function _getTableName() { return sprintf('%s%s', BaseOrm::getDbPrefix(), str_replace('\\', '_', $this->normalizeKey($this->modelName))); }
public function __construct($kwargs = []) { BaseOrm::configure($this, $kwargs, ['to' => 'toModel']); }
public function __construct($config = []) { BaseOrm::configure($this, $config, ['rel' => 'relation']); if ($this->relation !== null) { $this->isRelation = true; } }
public function getMigrationsFiles() { $fileHandler = FileHandler::createObject(['path' => BaseOrm::getMigrationsPath()]); return $fileHandler->getPathFiles(); }
public function check(InputInterface $input, OutputInterface $output, $tags = null, $showErrorCount = null, $failLevel = null) { $checks = BaseOrm::getCheckRegistry()->runChecks($tags); $debugs = []; $info = []; $warning = []; $errors = []; $critical = []; $serious = []; $header = $body = $footer = ''; /** @var $check CheckMessage */ foreach ($checks as $check) { if ($check->isSerious($failLevel) && !$check->isSilenced()) { $serious[] = $check; } if ($check->level < CheckMessage::INFO && !$check->isSilenced()) { $debugs[] = $check; } // info if ($check->level >= CheckMessage::INFO && $check->level < CheckMessage::WARNING && !$check->isSilenced()) { $info[] = $check; } // warning if ($check->level >= CheckMessage::WARNING && $check->level < CheckMessage::ERROR && !$check->isSilenced()) { $warning[] = $check; } //error if ($check->level >= CheckMessage::ERROR && $check->level < CheckMessage::CRITICAL && !$check->isSilenced()) { $errors[] = $check; } //critical if ($check->level >= CheckMessage::CRITICAL && !$check->isSilenced()) { $critical[] = $check; } } // get the count of visible issues only, hide the silenced ones $visibleIssues = count($errors) + count($warning) + count($info) + count($debugs) + count($critical); if ($visibleIssues) { $header = 'System check identified issues: ' . PHP_EOL; } $errors = array_merge($critical, $errors); $categorisedIssues = ['critical' => $critical, 'errors' => $errors, 'warning' => $warning, 'info' => $info, 'debug' => $debugs]; /* @var $catIssue CheckMessage */ foreach ($categorisedIssues as $category => $categoryIssues) { if (empty($categoryIssues)) { continue; } $body .= sprintf(PHP_EOL . ' %s' . PHP_EOL, strtoupper($category)); foreach ($categoryIssues as $catIssue) { if ($catIssue->isSerious()) { $msg = ' <errorText>%s</errorText>' . PHP_EOL; } else { $msg = ' <warning>%s</warning>' . PHP_EOL; } $body .= sprintf($msg, $catIssue); } } if ($showErrorCount) { $issueText = $visibleIssues === 1 ? 'issue' : 'issues'; $silenced = count($checks) - $visibleIssues; if ($visibleIssues) { $footer .= PHP_EOL; } $footer .= sprintf(' System check identified %s %s (%s silenced) ', $visibleIssues, $issueText, $silenced); } if (!empty($serious)) { $header = sprintf('<errorText> SystemCheckError: %s</errorText>', $header); $message = $header . $body . $footer; $output->writeln($message); throw new SystemCheckError(); } $message = $header . $body . $footer; $output->writeln($message); }
public static function consoleRun($config) { static::run($config); BaseOrm::consoleRunner(); }
public static function getCharset() { //todo make character set independent of framework return BaseOrm::getCharset(); }
/** * Defines a new model class. * * we create a new namespace and define new classes because, we might be dealing with a model that has been dropped * Meaning if we try to load the model using the normal way, we will get and error of model does not exist. * * @param string $className * @param string $extends * * @return Model * * @since 1.1.0 * * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**> */ private static function createInstance($className, $extends = '') { if (!ClassHelper::classExists($className, BaseOrm::getModelsNamespace())) { MigrationModel::defineClass($className, $extends); } return new $className(); }