From 426047e4e2fac80b4b5b67f1cb99160064f7a111 Mon Sep 17 00:00:00 2001 From: Yuji Iwai Date: Thu, 16 Aug 2018 16:50:23 +0900 Subject: [PATCH 01/50] bugfix: webtools modelsNamespace typo --- scripts/Phalcon/Web/Tools/Views/scaffold/generate.volt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/Phalcon/Web/Tools/Views/scaffold/generate.volt b/scripts/Phalcon/Web/Tools/Views/scaffold/generate.volt index 21af5d0cb..a5580a283 100644 --- a/scripts/Phalcon/Web/Tools/Views/scaffold/generate.volt +++ b/scripts/Phalcon/Web/Tools/Views/scaffold/generate.volt @@ -13,9 +13,9 @@
- +
- {{ input("modelNamespace", 'eg. My\Awesome\Namespace') }} + {{ input("modelsNamespace", 'eg. My\Awesome\Namespace') }}
From 5cd6e90f8fb25799586d51a7751f80ad589dad4c Mon Sep 17 00:00:00 2001 From: zcq <64899484@qq.com> Date: Fri, 12 Oct 2018 20:34:56 +0800 Subject: [PATCH 02/50] added: migration support multiple dir --- .../Phalcon/Commands/Builtin/Migration.php | 102 ++++++++------- scripts/Phalcon/Console/OptionParserTrait.php | 23 +++- scripts/Phalcon/Migrations.php | 121 ++++++++++++------ scripts/Phalcon/Version/IncrementalItem.php | 26 +++- .../migrations/1.0.13/test_many_running.php | 94 ++++++++++++++ tests/console/RunMultipleMigrationCept.php | 23 ++++ 6 files changed, 293 insertions(+), 96 deletions(-) create mode 100644 tests/_data/console/app/test_many_running_back/migrations/1.0.13/test_many_running.php create mode 100644 tests/console/RunMultipleMigrationCept.php diff --git a/scripts/Phalcon/Commands/Builtin/Migration.php b/scripts/Phalcon/Commands/Builtin/Migration.php index 9bb46a6fd..6bcec4bb6 100644 --- a/scripts/Phalcon/Commands/Builtin/Migration.php +++ b/scripts/Phalcon/Commands/Builtin/Migration.php @@ -26,6 +26,7 @@ use Phalcon\Migrations; use Phalcon\Config; + /** * Migration Command * @@ -43,21 +44,21 @@ class Migration extends Command public function getPossibleParams() { return [ - 'action=s' => 'Generates a Migration [generate|run]', - 'config=s' => 'Configuration file', - 'migrations=s' => 'Migrations directory', - 'directory=s' => 'Directory where the project was created', - 'table=s' => 'Table to migrate. Table name or table prefix with asterisk. Default: all', - 'version=s' => 'Version to migrate', - 'descr=s' => 'Migration description (used for timestamp based migration)', - 'data=s' => 'Export data [always|oncreate] (Import data when run migration)', - 'force' => 'Forces to overwrite existing migrations', - 'ts-based' => 'Timestamp based migration version', - 'log-in-db' => 'Keep migrations log in the database table rather than in file', - 'dry' => 'Attempt requested operation without making changes to system (Generating only)', - 'verbose' => 'Output of debugging information during operation (Running only)', + 'action=s' => 'Generates a Migration [generate|run]', + 'config=s' => 'Configuration file', + 'migrations=s' => 'Migrations directory,multiple dir use `,` separate', + 'directory=s' => 'Directory where the project was created', + 'table=s' => 'Table to migrate. Table name or table prefix with asterisk. Default: all', + 'version=s' => 'Version to migrate', + 'descr=s' => 'Migration description (used for timestamp based migration)', + 'data=s' => 'Export data [always|oncreate] (Import data when run migration)', + 'force' => 'Forces to overwrite existing migrations', + 'ts-based' => 'Timestamp based migration version', + 'log-in-db' => 'Keep migrations log in the database table rather than in file', + 'dry' => 'Attempt requested operation without making changes to system (Generating only)', + 'verbose' => 'Output of debugging information during operation (Running only)', 'no-auto-increment' => 'Disable auto increment (Generating only)', - 'help' => 'Shows this help [optional]', + 'help' => 'Shows this help [optional]', ]; } @@ -79,21 +80,31 @@ public function run(array $parameters) $config = $this->getConfig($path); } + + //multiple dir + $migrationsDir = []; if ($this->isReceivedOption('migrations')) { - $migrationsDir = $path . $this->getOption('migrations'); + $migrationsDir = explode(',', $this->getOption('migrations')); } elseif (isset($config['application']['migrationsDir'])) { - $migrationsDir = $config['application']['migrationsDir']; - if (!$this->path->isAbsolutePath($migrationsDir)) { - $migrationsDir = $path . $migrationsDir; + $migrationsDir = explode(',', $config['application']['migrationsDir']); + } + + + if (!empty($migrationsDir)) { + foreach ($migrationsDir as $id => $dir) { + if (!$this->path->isAbsolutePath($dir)) { + $migrationsDir[$id] = $path . $dir; + } } } elseif (file_exists($path . 'app')) { - $migrationsDir = $path . 'app/migrations'; + $migrationsDir[] = $path . 'app/migrations'; } elseif (file_exists($path . 'apps')) { - $migrationsDir = $path . 'apps/migrations'; + $migrationsDir[] = $path . 'apps/migrations'; } else { - $migrationsDir = $path . 'migrations'; + $migrationsDir[] = $path . 'migrations'; } + // keep migrations log in db // either "log-in-db" option or "logInDb" config variable from "application" block $migrationsInDb = false; @@ -114,44 +125,43 @@ public function run(array $parameters) $tableName = $this->isReceivedOption('table') ? $this->getOption('table') : '@'; $action = $this->getOption(['action', 1]); - switch ($action) { case 'generate': Migrations::generate([ - 'directory' => $path, - 'tableName' => $tableName, - 'exportData' => $this->getOption('data'), - 'migrationsDir' => $migrationsDir, - 'version' => $this->getOption('version'), - 'force' => $this->isReceivedOption('force'), + 'directory' => $path, + 'tableName' => $tableName, + 'exportData' => $this->getOption('data'), + 'migrationsDir' => $migrationsDir, + 'version' => $this->getOption('version'), + 'force' => $this->isReceivedOption('force'), 'noAutoIncrement' => $this->isReceivedOption('no-auto-increment'), - 'config' => $config, - 'descr' => $this->getOption('descr'), - 'verbose' => $this->isReceivedOption('dry'), + 'config' => $config, + 'descr' => $this->getOption('descr'), + 'verbose' => $this->isReceivedOption('dry'), ]); break; case 'run': Migrations::run([ - 'directory' => $path, - 'tableName' => $tableName, - 'migrationsDir' => $migrationsDir, - 'force' => $this->isReceivedOption('force'), - 'tsBased' => $migrationsTsBased, - 'config' => $config, - 'version' => $this->getOption('version'), + 'directory' => $path, + 'tableName' => $tableName, + 'migrationsDir' => $migrationsDir, + 'force' => $this->isReceivedOption('force'), + 'tsBased' => $migrationsTsBased, + 'config' => $config, + 'version' => $this->getOption('version'), 'migrationsInDb' => $migrationsInDb, - 'verbose' => $this->isReceivedOption('verbose'), + 'verbose' => $this->isReceivedOption('verbose'), ]); break; case 'list': Migrations::listAll([ - 'directory' => $path, - 'tableName' => $tableName, - 'migrationsDir' => $migrationsDir, - 'force' => $this->isReceivedOption('force'), - 'tsBased' => $migrationsTsBased, - 'config' => $config, - 'version' => $this->getOption('version'), + 'directory' => $path, + 'tableName' => $tableName, + 'migrationsDir' => $migrationsDir, + 'force' => $this->isReceivedOption('force'), + 'tsBased' => $migrationsTsBased, + 'config' => $config, + 'version' => $this->getOption('version'), 'migrationsInDb' => $migrationsInDb, ]); break; diff --git a/scripts/Phalcon/Console/OptionParserTrait.php b/scripts/Phalcon/Console/OptionParserTrait.php index a1535566f..64db59aa6 100644 --- a/scripts/Phalcon/Console/OptionParserTrait.php +++ b/scripts/Phalcon/Console/OptionParserTrait.php @@ -38,8 +38,8 @@ trait OptionParserTrait /** * Get prefix from the option * - * @param string $prefix - * @param mixed $prefixEnd + * @param string $prefix + * @param mixed $prefixEnd * * @return mixed */ @@ -74,12 +74,27 @@ public function getVersionNameGeneratingMigration() } elseif ($this->options['version']) { VersionCollection::setType(VersionCollection::TYPE_INCREMENTAL); $versionItem = VersionCollection::createItem($this->options['version']); + //check version is exist + foreach ($this->options['migrationsDir'] ?? [] as $migrationsDir) { + foreach (ModelMigration::scanForVersions($migrationsDir) ?? [] as $item) { + if ($item->getVersion() != $versionItem->getVersion()) { + continue; + } + if (!$optionStack->getOption('force')) { + throw new \LogicException('Version ' . $item->getVersion() . ' already exists'); + } else { + rmdir(rtrim($migrationsDir, '\\/') . DIRECTORY_SEPARATOR . $versionItem->getVersion()); + } + } + } // The version is guessed automatically } else { VersionCollection::setType(VersionCollection::TYPE_INCREMENTAL); - $versionItems = ModelMigration::scanForVersions($this->options['migrationsDir']); - + $versionItems = []; + foreach ($this->options['migrationsDir'] ?? [] as $migrationsDir) { + $versionItems = $versionItems + ModelMigration::scanForVersions($migrationsDir); + } if (!isset($versionItems[0])) { $versionItem = VersionCollection::createItem('1.0.0'); } else { diff --git a/scripts/Phalcon/Migrations.php b/scripts/Phalcon/Migrations.php index 8791eb13c..6f3e7fb4b 100644 --- a/scripts/Phalcon/Migrations.php +++ b/scripts/Phalcon/Migrations.php @@ -85,15 +85,34 @@ public static function generate(array $options) $optionStack->setDefaultOption('noAutoIncrement', null); $optionStack->setDefaultOption('verbose', false); + $migrationsDirs = $optionStack->getOption('migrationsDir'); + //select multiple dir + if (count($migrationsDirs) > 1) { + $question = 'Which migrations path would you like to use?' . PHP_EOL; + foreach ($migrationsDirs as $id => $dir) { + $question .= " [{$id}] $dir" . PHP_EOL; + } + fwrite(STDOUT, Color::info($question)); + $handle = fopen("php://stdin", "r"); + $line = (int)fgets($handle); + if (!isset($migrationsDirs[$line])) { + echo "ABORTING!\n"; + return false; + } + fclose($handle); + $migrationsDir = $migrationsDirs[$line]; + } else { + $migrationsDir = $migrationsDirs[0]; + } // Migrations directory - if ($optionStack->getOption('migrationsDir') && !file_exists($optionStack->getOption('migrationsDir'))) { - mkdir($optionStack->getOption('migrationsDir'), 0755, true); + if ($migrationsDir && !file_exists($migrationsDir)) { + mkdir($migrationsDir, 0755, true); } $versionItem = $optionStack->getVersionNameGeneratingMigration(); // Path to migration dir - $migrationPath = rtrim($optionStack->getOption('migrationsDir'), '\\/') . + $migrationPath = rtrim($migrationsDir, '\\/') . DIRECTORY_SEPARATOR . $versionItem->getVersion(); if (!file_exists($migrationPath)) { @@ -113,7 +132,7 @@ public static function generate(array $options) ModelMigration::setup($optionStack->getOption('config')->database, $optionStack->getOption('verbose')); ModelMigration::setSkipAutoIncrement($optionStack->getOption('noAutoIncrement')); - ModelMigration::setMigrationPath($optionStack->getOption('migrationsDir')); + ModelMigration::setMigrationPath($migrationsDir); $wasMigrated = false; if ($optionStack->getOption('tableName') === '@') { @@ -125,9 +144,9 @@ public static function generate(array $options) } $tableFile = $migrationPath . DIRECTORY_SEPARATOR . $tableName . '.php'; $wasMigrated = file_put_contents( - $tableFile, - 'getOption('migrationsDir'), '\\/'); - if (!file_exists($migrationsDir)) { - throw new ModelException('Migrations directory was not found.'); - } if (!$optionStack->getOption('config') instanceof Config) { throw new ModelException('Internal error. Config should be an instance of ' . Config::class); @@ -199,6 +214,23 @@ public static function run(array $options) throw new ScriptException('Cannot load database configuration'); } + /** @var \Phalcon\Version\IncrementalItem $initialVersion */ + $initialVersion = self::getCurrentVersion($optionStack->getOptions()); + $completedVersions = self::getCompletedVersions($optionStack->getOptions()); + + $migrationsDirs = []; + $versionItems = []; + foreach ($optionStack->getOption('migrationsDir') ?? [] as $migrationsDir) { + $migrationsDir = rtrim($migrationsDir, '\\/'); + if (!file_exists($migrationsDir)) { + throw new ModelException('Migrations directory was not found.'); + } + $migrationsDirs[] = $migrationsDir; + foreach (ModelMigration::scanForVersions($migrationsDir) ?? [] as $items) { + $items->setPath($migrationsDir); + $versionItems [] = $items; + } + } $finalVersion = null; if (isset($options['version']) && $optionStack->getOption('version') !== null) { $finalVersion = VersionCollection::createItem($options['version']); @@ -206,14 +238,13 @@ public static function run(array $options) $optionStack->setOption('tableName', $options['tableName'], '@'); - $versionItems = ModelMigration::scanForVersions($migrationsDir); if (!isset($versionItems[0])) { if (php_sapi_name() == 'cli') { - fwrite(STDERR, PHP_EOL . 'Migrations were not found at ' . $migrationsDir . PHP_EOL); + fwrite(STDERR, PHP_EOL . 'Migrations were not found at ' . $optionStack->getOption('migrationsDir') . PHP_EOL); exit; } else { - throw new ModelException('Migrations were not found at ' . $migrationsDir); + throw new ModelException('Migrations were not found at ' . $optionStack->getOption('migrationsDir')); } } @@ -223,13 +254,8 @@ public static function run(array $options) } ModelMigration::setup($optionStack->getOption('config')->database, $optionStack->getOption('verbose')); - ModelMigration::setMigrationPath($migrationsDir); self::connectionSetup($optionStack->getOptions()); - /** @var \Phalcon\Version\IncrementalItem $initialVersion */ - $initialVersion = self::getCurrentVersion($optionStack->getOptions()); - $completedVersions = self::getCompletedVersions($optionStack->getOptions()); - // Everything is up to date if ($initialVersion->getStamp() === $finalVersion->getStamp()) { print Color::info('Everything is up to date'); @@ -260,6 +286,17 @@ public static function run(array $options) /** @var \Phalcon\Version\IncrementalItem $versionItem */ foreach ($versionsBetween as $versionItem) { + $migrationsDir = $versionItem->getPath(); + ModelMigration::setMigrationPath($migrationsDir); + + // Directory depends on Forward or Back Migration + $directoryIterator = $migrationsDir . DIRECTORY_SEPARATOR . (ModelMigration::DIRECTION_BACK === $direction ? + $initialVersion->getVersion() : $versionItem->getVersion()); + if (!is_dir($directoryIterator)) { + continue; + } + $iterator = new DirectoryIterator($directoryIterator); + // If we are rolling back, we skip migrating when initialVersion is the same as current if ($initialVersion->getVersion() === $versionItem->getVersion() && ModelMigration::DIRECTION_BACK === $direction) { @@ -283,11 +320,6 @@ public static function run(array $options) $migrationStartTime = date("Y-m-d H:i:s"); - // Directory depends on Forward or Back Migration - $iterator = new DirectoryIterator( - $migrationsDir . DIRECTORY_SEPARATOR . (ModelMigration::DIRECTION_BACK === $direction ? - $initialVersion->getVersion() : $versionItem->getVersion()) - ); if ($optionStack->getOption('tableName') === '@') { foreach ($iterator as $fileInfo) { @@ -301,7 +333,7 @@ public static function run(array $options) $optionStack->setOption('tableName', $listTables->listTablesForPrefix($prefix, $iterator)); } - $tables = explode(',', $optionStack->getOption('tableName')); + $tables = explode(',', $optionStack->getOption('tableName')); foreach ($tables as $tableName) { ModelMigration::migrate($initialVersion, $versionItem, $tableName); } @@ -317,6 +349,7 @@ public static function run(array $options) $initialVersion = $versionItem; } + } /** @@ -338,10 +371,6 @@ public static function listAll(array $options) VersionCollection::setType(VersionCollection::TYPE_INCREMENTAL); } - $migrationsDir = rtrim($options['migrationsDir'], '/'); - if (!file_exists($migrationsDir)) { - throw new ModelException('Migrations directory was not found.'); - } /** @var Config $config */ $config = $options['config']; @@ -353,16 +382,24 @@ public static function listAll(array $options) if (!isset($config->database)) { throw new ScriptException('Cannot load database configuration'); } + $versionItems = []; + foreach ($options['migrationsDir'] ?? [] as $migrationsDir) { + $migrationsDir = rtrim($migrationsDir, '/'); + if (!file_exists($migrationsDir)) { + throw new ModelException('Migrations directory was not found.'); + } + $versionItem = ModelMigration::scanForVersions($migrationsDir); - $versionItems = ModelMigration::scanForVersions($migrationsDir); - - if (!isset($versionItems[0])) { - print Color::info('Migrations were not found at ' . $migrationsDir); - return; + if (!isset($versionItem[0])) { + print Color::info('Migrations were not found at ' . $migrationsDir); + return; + } + $versionItems = $versionItems + $versionItem; } + ModelMigration::setup($config->database); - ModelMigration::setMigrationPath($migrationsDir); + self::connectionSetup($options); $completedVersions = self::getCompletedVersions($options); @@ -383,14 +420,14 @@ public static function listAll(array $options) } $header = sprintf($format, 'Version', 'Was applied'); - $report[] = '├' . str_repeat('─', $versionColumnWidth) . '┼'. str_repeat('─', 14) . '┤'; + $report[] = '├' . str_repeat('─', $versionColumnWidth) . '┼' . str_repeat('─', 14) . '┤'; $report[] = $header; $report = array_reverse($report); - echo '┌' . str_repeat('─', $versionColumnWidth) . '┬'. str_repeat('─', 14) . '┐' . PHP_EOL; + echo '┌' . str_repeat('─', $versionColumnWidth) . '┬' . str_repeat('─', 14) . '┐' . PHP_EOL; echo join(PHP_EOL, $report) . PHP_EOL; - echo '└' . str_repeat('─', $versionColumnWidth) . '┴'. str_repeat('─', 14) . '┘'. PHP_EOL . PHP_EOL; + echo '└' . str_repeat('─', $versionColumnWidth) . '┴' . str_repeat('─', 14) . '┘' . PHP_EOL . PHP_EOL; } /** @@ -503,7 +540,7 @@ public static function getCurrentVersion($options) if (isset($options['migrationsInDb']) && (bool)$options['migrationsInDb']) { /** @var AdapterInterface $connection */ $connection = self::$storage; - $query = 'SELECT * FROM '. self::MIGRATION_LOG_TABLE .' ORDER BY version DESC LIMIT 1'; + $query = 'SELECT * FROM ' . self::MIGRATION_LOG_TABLE . ' ORDER BY version DESC LIMIT 1'; $lastGoodMigration = $connection->query($query); if (0 == $lastGoodMigration->numRows()) { @@ -543,7 +580,7 @@ public static function addCurrentVersion($options, $version, $startTime = null) } $endTime = date("Y-m-d H:i:s"); - if (isset($options['migrationsInDb']) && (bool) $options['migrationsInDb']) { + if (isset($options['migrationsInDb']) && (bool)$options['migrationsInDb']) { /** @var AdapterInterface $connection */ $connection = self::$storage; $connection->insert( @@ -573,7 +610,7 @@ public static function removeCurrentVersion($options, $version) if (isset($options['migrationsInDb']) && (bool)$options['migrationsInDb']) { /** @var AdapterInterface $connection */ $connection = self::$storage; - $connection->execute('DELETE FROM '. self::MIGRATION_LOG_TABLE .' WHERE version=\'' . $version . '\''); + $connection->execute('DELETE FROM ' . self::MIGRATION_LOG_TABLE . ' WHERE version=\'' . $version . '\''); } else { $currentVersions = self::getCompletedVersions($options); unset($currentVersions[$version]); @@ -602,6 +639,8 @@ public static function getCompletedVersions($options) return $version['version']; }, $completedVersions); } else { + var_dump(self::$storage); + die; $completedVersions = file(self::$storage, FILE_IGNORE_NEW_LINES); } diff --git a/scripts/Phalcon/Version/IncrementalItem.php b/scripts/Phalcon/Version/IncrementalItem.php index e97047e68..fea61c04d 100644 --- a/scripts/Phalcon/Version/IncrementalItem.php +++ b/scripts/Phalcon/Version/IncrementalItem.php @@ -33,6 +33,12 @@ class IncrementalItem implements ItemInterface { use VersionAwareTrait; + + /** + * @var string + */ + private $path; + /** * @var string */ @@ -50,7 +56,7 @@ class IncrementalItem implements ItemInterface /** * @param string $version - * @param int $numberParts + * @param int $numberParts */ public function __construct($version, $numberParts = 3) { @@ -61,12 +67,12 @@ public function __construct($version, $numberParts = 3) if ($nParts < $numberParts) { for ($i = $numberParts; $i >= $nParts; $i--) { $this->parts[] = '0'; - $version.='.0'; + $version .= '.0'; } } elseif ($nParts > $numberParts) { for ($i = $nParts; $i <= $numberParts; $i++) { - if (isset($this->parts[$i-1])) { - unset($this->parts[$i-1]); + if (isset($this->parts[$i - 1])) { + unset($this->parts[$i - 1]); } } @@ -166,7 +172,7 @@ public static function between($initialVersion, $finalVersion, $versions) } } - return $betweenVersions ; + return $betweenVersions; } /** @@ -216,6 +222,16 @@ public function getVersion() return $this->version; } + public function getPath() + { + return $this->path; + } + + public function setPath($path) + { + $this->path = $path; + } + protected function regenerateVersionStamp() { $n = 2; diff --git a/tests/_data/console/app/test_many_running_back/migrations/1.0.13/test_many_running.php b/tests/_data/console/app/test_many_running_back/migrations/1.0.13/test_many_running.php new file mode 100644 index 000000000..16ceb683e --- /dev/null +++ b/tests/_data/console/app/test_many_running_back/migrations/1.0.13/test_many_running.php @@ -0,0 +1,94 @@ +morphTable('test_many_running', [ + 'columns' => [ + new Column( + 'id', + [ + 'type' => Column::TYPE_INTEGER, + 'unsigned' => true, + 'notNull' => true, + 'autoIncrement' => true, + 'size' => 10, + 'first' => true + ] + ), + new Column( + 'name', + [ + 'type' => Column::TYPE_VARCHAR, + 'notNull' => true, + 'size' => 45, + 'after' => 'id' + ] + ), + new Column( + 'created_at', + [ + 'type' => Column::TYPE_DATETIME, + 'notNull' => true, + 'size' => 1, + 'after' => 'name' + ] + ), + new Column( + 'active', + [ + 'type' => Column::TYPE_INTEGER, + 'notNull' => true, + 'size' => 1, + 'after' => 'created_at' + ] + ) + ], + 'indexes' => [ + new Index('PRIMARY', ['id'], 'PRIMARY') + ], + 'options' => [ + 'TABLE_TYPE' => 'BASE TABLE', + 'AUTO_INCREMENT' => '1', + 'ENGINE' => 'InnoDB', + 'TABLE_COLLATION' => 'utf8_general_ci' + ], + ] + ); + } + + /** + * Run the migrations + * + * @return void + */ + public function up() + { + + } + + /** + * Reverse the migrations + * + * @return void + */ + public function down() + { + + } + +} diff --git a/tests/console/RunMultipleMigrationCept.php b/tests/console/RunMultipleMigrationCept.php new file mode 100644 index 000000000..a6fb92f30 --- /dev/null +++ b/tests/console/RunMultipleMigrationCept.php @@ -0,0 +1,23 @@ +wantToTest('Running migration using migration file from .phalcon folder'); + +$I->amInPath(dirname(app_path())); +$I->cleanDir(tests_path('_data/console/.phalcon')); + +$I->runShellCommand('phalcon migration --action=run --config=app/mysql/config.php --migrations=app/test_many_running/migrations,app/test_many_running/migrations --table=test_many_running'); +$I->seeInShellOutput('Success: Version 1.0.12 was successfully migrated'); + +$I->runShellCommand('phalcon migration --action=run --config=app/mysql/config.php --migrations=app/test_many_running/migrations,app/test_many_running/migrations --table=test_many_running --version=1.0.12'); +$I->seeInShellOutput('Success: Version 1.0.13 was successfully rolled back'); + +$I->runShellCommand('phalcon migration --action=run --config=app/mysql/config.php --migrations=app/test_many_running/migrations,app/test_many_running/migrations --table=test_many_running --version=1.0.13'); +$I->seeInShellOutput('Success: Version 1.0.13 was successfully migrated'); + +$I->cleanDir(tests_path('_data/console/.phalcon')); From 6a3bf5d52798c60f953d4a54b91c93587121be12 Mon Sep 17 00:00:00 2001 From: zcq <64899484@qq.com> Date: Sat, 13 Oct 2018 00:44:18 +0800 Subject: [PATCH 03/50] fix: test file dir error --- .../Phalcon/Commands/Builtin/Migration.php | 50 +++++------ scripts/Phalcon/Console/OptionParserTrait.php | 31 ++++--- scripts/Phalcon/Migrations.php | 86 ++++++++++--------- scripts/Phalcon/Version/IncrementalItem.php | 10 +-- scripts/Phalcon/Version/ItemInterface.php | 16 ++++ scripts/Phalcon/Version/TimestampedItem.php | 27 ++++++ .../1.0.13/test_many_running.php | 0 tests/console/RunMultipleMigrationCept.php | 10 +-- 8 files changed, 145 insertions(+), 85 deletions(-) rename tests/_data/console/app/{test_many_running_back/migrations => test_many_running/migrations_back}/1.0.13/test_many_running.php (100%) diff --git a/scripts/Phalcon/Commands/Builtin/Migration.php b/scripts/Phalcon/Commands/Builtin/Migration.php index 6bcec4bb6..4676c9afb 100644 --- a/scripts/Phalcon/Commands/Builtin/Migration.php +++ b/scripts/Phalcon/Commands/Builtin/Migration.php @@ -26,7 +26,6 @@ use Phalcon\Migrations; use Phalcon\Config; - /** * Migration Command * @@ -125,43 +124,44 @@ public function run(array $parameters) $tableName = $this->isReceivedOption('table') ? $this->getOption('table') : '@'; $action = $this->getOption(['action', 1]); + switch ($action) { case 'generate': Migrations::generate([ - 'directory' => $path, - 'tableName' => $tableName, - 'exportData' => $this->getOption('data'), - 'migrationsDir' => $migrationsDir, - 'version' => $this->getOption('version'), - 'force' => $this->isReceivedOption('force'), + 'directory' => $path, + 'tableName' => $tableName, + 'exportData' => $this->getOption('data'), + 'migrationsDir' => $migrationsDir, + 'version' => $this->getOption('version'), + 'force' => $this->isReceivedOption('force'), 'noAutoIncrement' => $this->isReceivedOption('no-auto-increment'), - 'config' => $config, - 'descr' => $this->getOption('descr'), - 'verbose' => $this->isReceivedOption('dry'), + 'config' => $config, + 'descr' => $this->getOption('descr'), + 'verbose' => $this->isReceivedOption('dry'), ]); break; case 'run': Migrations::run([ - 'directory' => $path, - 'tableName' => $tableName, - 'migrationsDir' => $migrationsDir, - 'force' => $this->isReceivedOption('force'), - 'tsBased' => $migrationsTsBased, - 'config' => $config, - 'version' => $this->getOption('version'), + 'directory' => $path, + 'tableName' => $tableName, + 'migrationsDir' => $migrationsDir, + 'force' => $this->isReceivedOption('force'), + 'tsBased' => $migrationsTsBased, + 'config' => $config, + 'version' => $this->getOption('version'), 'migrationsInDb' => $migrationsInDb, - 'verbose' => $this->isReceivedOption('verbose'), + 'verbose' => $this->isReceivedOption('verbose'), ]); break; case 'list': Migrations::listAll([ - 'directory' => $path, - 'tableName' => $tableName, - 'migrationsDir' => $migrationsDir, - 'force' => $this->isReceivedOption('force'), - 'tsBased' => $migrationsTsBased, - 'config' => $config, - 'version' => $this->getOption('version'), + 'directory' => $path, + 'tableName' => $tableName, + 'migrationsDir' => $migrationsDir, + 'force' => $this->isReceivedOption('force'), + 'tsBased' => $migrationsTsBased, + 'config' => $config, + 'version' => $this->getOption('version'), 'migrationsInDb' => $migrationsInDb, ]); break; diff --git a/scripts/Phalcon/Console/OptionParserTrait.php b/scripts/Phalcon/Console/OptionParserTrait.php index 64db59aa6..b267f8933 100644 --- a/scripts/Phalcon/Console/OptionParserTrait.php +++ b/scripts/Phalcon/Console/OptionParserTrait.php @@ -75,15 +75,21 @@ public function getVersionNameGeneratingMigration() VersionCollection::setType(VersionCollection::TYPE_INCREMENTAL); $versionItem = VersionCollection::createItem($this->options['version']); //check version is exist - foreach ($this->options['migrationsDir'] ?? [] as $migrationsDir) { - foreach (ModelMigration::scanForVersions($migrationsDir) ?? [] as $item) { - if ($item->getVersion() != $versionItem->getVersion()) { - continue; - } - if (!$optionStack->getOption('force')) { - throw new \LogicException('Version ' . $item->getVersion() . ' already exists'); - } else { - rmdir(rtrim($migrationsDir, '\\/') . DIRECTORY_SEPARATOR . $versionItem->getVersion()); + $migrationsDirList = $this->options['migrationsDir']; + if (is_array($migrationsDirList)) { + foreach ($migrationsDirList as $migrationsDir) { + $migrationsDirList = ModelMigration::scanForVersions($migrationsDir); + if (is_array($migrationsDirList)) { + foreach ($migrationsDirList as $item) { + if ($item->getVersion() != $versionItem->getVersion()) { + continue; + } + if (!$this->options['force']) { + throw new \LogicException('Version ' . $item->getVersion() . ' already exists'); + } else { + rmdir(rtrim($migrationsDir, '\\/') . DIRECTORY_SEPARATOR . $versionItem->getVersion()); + } + } } } } @@ -92,8 +98,11 @@ public function getVersionNameGeneratingMigration() } else { VersionCollection::setType(VersionCollection::TYPE_INCREMENTAL); $versionItems = []; - foreach ($this->options['migrationsDir'] ?? [] as $migrationsDir) { - $versionItems = $versionItems + ModelMigration::scanForVersions($migrationsDir); + $migrationsDirList = $this->options['migrationsDir']; + if (is_array($migrationsDirList)) { + foreach ($migrationsDirList as $migrationsDir) { + $versionItems = $versionItems + ModelMigration::scanForVersions($migrationsDir); + } } if (!isset($versionItems[0])) { $versionItem = VersionCollection::createItem('1.0.0'); diff --git a/scripts/Phalcon/Migrations.php b/scripts/Phalcon/Migrations.php index 6f3e7fb4b..80b19f0b0 100644 --- a/scripts/Phalcon/Migrations.php +++ b/scripts/Phalcon/Migrations.php @@ -144,9 +144,9 @@ public static function generate(array $options) } $tableFile = $migrationPath . DIRECTORY_SEPARATOR . $tableName . '.php'; $wasMigrated = file_put_contents( - $tableFile, - 'getOptions()); $completedVersions = self::getCompletedVersions($optionStack->getOptions()); - $migrationsDirs = []; $versionItems = []; - foreach ($optionStack->getOption('migrationsDir') ?? [] as $migrationsDir) { - $migrationsDir = rtrim($migrationsDir, '\\/'); - if (!file_exists($migrationsDir)) { - throw new ModelException('Migrations directory was not found.'); - } - $migrationsDirs[] = $migrationsDir; - foreach (ModelMigration::scanForVersions($migrationsDir) ?? [] as $items) { - $items->setPath($migrationsDir); - $versionItems [] = $items; + $migrationsDirList = $optionStack->getOption('migrationsDir'); + if (is_array($migrationsDirList)) { + foreach ($migrationsDirList as $migrationsDir) { + $migrationsDir = rtrim($migrationsDir, '\\/'); + if (!file_exists($migrationsDir)) { + throw new ModelException('Migrations directory was not found.'); + } + $migrationsDirs[] = $migrationsDir; + foreach (ModelMigration::scanForVersions($migrationsDir) as $items) { + $items->setPath($migrationsDir); + $versionItems [] = $items; + } } } + $finalVersion = null; if (isset($options['version']) && $optionStack->getOption('version') !== null) { $finalVersion = VersionCollection::createItem($options['version']); @@ -241,7 +244,8 @@ public static function run(array $options) if (!isset($versionItems[0])) { if (php_sapi_name() == 'cli') { - fwrite(STDERR, PHP_EOL . 'Migrations were not found at ' . $optionStack->getOption('migrationsDir') . PHP_EOL); + fwrite(STDERR, PHP_EOL . 'Migrations were not found at ' . + $optionStack->getOption('migrationsDir') . PHP_EOL); exit; } else { throw new ModelException('Migrations were not found at ' . $optionStack->getOption('migrationsDir')); @@ -286,23 +290,15 @@ public static function run(array $options) /** @var \Phalcon\Version\IncrementalItem $versionItem */ foreach ($versionsBetween as $versionItem) { - $migrationsDir = $versionItem->getPath(); - ModelMigration::setMigrationPath($migrationsDir); - - // Directory depends on Forward or Back Migration - $directoryIterator = $migrationsDir . DIRECTORY_SEPARATOR . (ModelMigration::DIRECTION_BACK === $direction ? - $initialVersion->getVersion() : $versionItem->getVersion()); - if (!is_dir($directoryIterator)) { - continue; + if ($initialVersion->getVersion() == $versionItem->getVersion()) { + $initialVersion->setPath($versionItem->getPath()); } - $iterator = new DirectoryIterator($directoryIterator); - + // If we are rolling back, we skip migrating when initialVersion is the same as current if ($initialVersion->getVersion() === $versionItem->getVersion() && ModelMigration::DIRECTION_BACK === $direction) { continue; } - if ((ModelMigration::DIRECTION_FORWARD === $direction) && isset($completedVersions[(string)$versionItem])) { print Color::info('Version ' . (string)$versionItem . ' was already applied'); continue; @@ -312,7 +308,20 @@ public static function run(array $options) $initialVersion = $versionItem; continue; } + //Directory depends on Forward or Back Migration + if (ModelMigration::DIRECTION_BACK === $direction) { + $migrationsDir = $initialVersion->getPath(); + $directoryIterator = $migrationsDir . DIRECTORY_SEPARATOR.$initialVersion->getVersion(); + } else { + $migrationsDir = $versionItem->getPath(); + $directoryIterator = $migrationsDir . DIRECTORY_SEPARATOR.$versionItem->getVersion(); + } + ModelMigration::setMigrationPath($migrationsDir); + if (!is_dir($directoryIterator)) { + continue; + } + $iterator = new DirectoryIterator($directoryIterator); if ($initialVersion->getVersion() === $finalVersion->getVersion() && ModelMigration::DIRECTION_BACK === $direction) { break; @@ -349,7 +358,6 @@ public static function run(array $options) $initialVersion = $versionItem; } - } /** @@ -383,21 +391,23 @@ public static function listAll(array $options) throw new ScriptException('Cannot load database configuration'); } $versionItems = []; - foreach ($options['migrationsDir'] ?? [] as $migrationsDir) { - $migrationsDir = rtrim($migrationsDir, '/'); - if (!file_exists($migrationsDir)) { - throw new ModelException('Migrations directory was not found.'); - } - $versionItem = ModelMigration::scanForVersions($migrationsDir); + $migrationsDirList = $options['migrationsDir']; + if (is_array($migrationsDirList)) { + foreach ($migrationsDirList as $migrationsDir) { + $migrationsDir = rtrim($migrationsDir, '/'); + if (!file_exists($migrationsDir)) { + throw new ModelException('Migrations directory was not found.'); + } + $versionItem = ModelMigration::scanForVersions($migrationsDir); - if (!isset($versionItem[0])) { - print Color::info('Migrations were not found at ' . $migrationsDir); - return; + if (!isset($versionItem[0])) { + print Color::info('Migrations were not found at ' . $migrationsDir); + return; + } + $versionItems = $versionItems + $versionItem; } - $versionItems = $versionItems + $versionItem; } - ModelMigration::setup($config->database); self::connectionSetup($options); @@ -639,8 +649,6 @@ public static function getCompletedVersions($options) return $version['version']; }, $completedVersions); } else { - var_dump(self::$storage); - die; $completedVersions = file(self::$storage, FILE_IGNORE_NEW_LINES); } diff --git a/scripts/Phalcon/Version/IncrementalItem.php b/scripts/Phalcon/Version/IncrementalItem.php index fea61c04d..03ad113c3 100644 --- a/scripts/Phalcon/Version/IncrementalItem.php +++ b/scripts/Phalcon/Version/IncrementalItem.php @@ -56,7 +56,7 @@ class IncrementalItem implements ItemInterface /** * @param string $version - * @param int $numberParts + * @param int $numberParts */ public function __construct($version, $numberParts = 3) { @@ -67,12 +67,12 @@ public function __construct($version, $numberParts = 3) if ($nParts < $numberParts) { for ($i = $numberParts; $i >= $nParts; $i--) { $this->parts[] = '0'; - $version .= '.0'; + $version.='.0'; } } elseif ($nParts > $numberParts) { for ($i = $nParts; $i <= $numberParts; $i++) { - if (isset($this->parts[$i - 1])) { - unset($this->parts[$i - 1]); + if (isset($this->parts[$i-1])) { + unset($this->parts[$i-1]); } } @@ -172,7 +172,7 @@ public static function between($initialVersion, $finalVersion, $versions) } } - return $betweenVersions; + return $betweenVersions ; } /** diff --git a/scripts/Phalcon/Version/ItemInterface.php b/scripts/Phalcon/Version/ItemInterface.php index ae594e099..4271666c2 100644 --- a/scripts/Phalcon/Version/ItemInterface.php +++ b/scripts/Phalcon/Version/ItemInterface.php @@ -50,4 +50,20 @@ public function getVersion(); * @return string */ public function __toString(); + + /** + * Set integer payload of the Path + * + * @param $path + * @return integer + */ + public function setPath($path); + + + /** + * Get integer payload of the Path + * + * @return integer + */ + public function getPath(); } diff --git a/scripts/Phalcon/Version/TimestampedItem.php b/scripts/Phalcon/Version/TimestampedItem.php index 1ba975a40..8c4436a19 100644 --- a/scripts/Phalcon/Version/TimestampedItem.php +++ b/scripts/Phalcon/Version/TimestampedItem.php @@ -32,6 +32,11 @@ class TimestampedItem implements ItemInterface { use VersionAwareTrait; + /** + * @var string + */ + private $path; + /** * @var string */ @@ -92,4 +97,26 @@ public function getDescription() { return $this->isFullVersion() ? $this->parts[1] : ''; } + + /** + * Set integer payload of the Path + * + * @param $path + * @return integer + */ + public function setPath($path) + { + $this->path = $path; + } + + + /** + * Get integer payload of the Path + * + * @return integer + */ + public function getPath() + { + return $this->path; + } } diff --git a/tests/_data/console/app/test_many_running_back/migrations/1.0.13/test_many_running.php b/tests/_data/console/app/test_many_running/migrations_back/1.0.13/test_many_running.php similarity index 100% rename from tests/_data/console/app/test_many_running_back/migrations/1.0.13/test_many_running.php rename to tests/_data/console/app/test_many_running/migrations_back/1.0.13/test_many_running.php diff --git a/tests/console/RunMultipleMigrationCept.php b/tests/console/RunMultipleMigrationCept.php index a6fb92f30..f89e7c5f1 100644 --- a/tests/console/RunMultipleMigrationCept.php +++ b/tests/console/RunMultipleMigrationCept.php @@ -11,13 +11,13 @@ $I->amInPath(dirname(app_path())); $I->cleanDir(tests_path('_data/console/.phalcon')); -$I->runShellCommand('phalcon migration --action=run --config=app/mysql/config.php --migrations=app/test_many_running/migrations,app/test_many_running/migrations --table=test_many_running'); -$I->seeInShellOutput('Success: Version 1.0.12 was successfully migrated'); +$I->runShellCommand('phalcon migration --action=run --config=app/mysql/config.php --migrations=app/test_many_running/migrations,app/test_many_running/migrations_back --table=test_many_running'); +$I->seeInShellOutput('Success: Version 1.0.13 was successfully migrated'); -$I->runShellCommand('phalcon migration --action=run --config=app/mysql/config.php --migrations=app/test_many_running/migrations,app/test_many_running/migrations --table=test_many_running --version=1.0.12'); -$I->seeInShellOutput('Success: Version 1.0.13 was successfully rolled back'); +$I->runShellCommand('phalcon migration --action=run --config=app/mysql/config.php --migrations=app/test_many_running/migrations,app/test_many_running/migrations_back --table=test_many_running --version=1.0.9'); +$I->seeInShellOutput('Success: Version 1.0.10 was successfully rolled back'); -$I->runShellCommand('phalcon migration --action=run --config=app/mysql/config.php --migrations=app/test_many_running/migrations,app/test_many_running/migrations --table=test_many_running --version=1.0.13'); +$I->runShellCommand('phalcon migration --action=run --config=app/mysql/config.php --migrations=app/test_many_running/migrations,app/test_many_running/migrations_back --table=test_many_running --version=1.0.13'); $I->seeInShellOutput('Success: Version 1.0.13 was successfully migrated'); $I->cleanDir(tests_path('_data/console/.phalcon')); From 43981287570baf3eaa79f1903797b52b3915c671 Mon Sep 17 00:00:00 2001 From: zcq <64899484@qq.com> Date: Sat, 13 Oct 2018 00:53:01 +0800 Subject: [PATCH 04/50] doc: PHPDoc error --- scripts/Phalcon/Version/IncrementalItem.php | 12 ++++++++++-- scripts/Phalcon/Version/ItemInterface.php | 5 ++--- scripts/Phalcon/Version/TimestampedItem.php | 7 +++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/scripts/Phalcon/Version/IncrementalItem.php b/scripts/Phalcon/Version/IncrementalItem.php index 03ad113c3..036eae5b9 100644 --- a/scripts/Phalcon/Version/IncrementalItem.php +++ b/scripts/Phalcon/Version/IncrementalItem.php @@ -221,12 +221,20 @@ public function getVersion() { return $this->version; } - + /** + * Get integer payload of the Path + * + * @return string + */ public function getPath() { return $this->path; } - + /** + * Set integer payload of the Path + * + * @param string $path + */ public function setPath($path) { $this->path = $path; diff --git a/scripts/Phalcon/Version/ItemInterface.php b/scripts/Phalcon/Version/ItemInterface.php index 4271666c2..13a971e0e 100644 --- a/scripts/Phalcon/Version/ItemInterface.php +++ b/scripts/Phalcon/Version/ItemInterface.php @@ -54,8 +54,7 @@ public function __toString(); /** * Set integer payload of the Path * - * @param $path - * @return integer + * @param string $path */ public function setPath($path); @@ -63,7 +62,7 @@ public function setPath($path); /** * Get integer payload of the Path * - * @return integer + * @return string */ public function getPath(); } diff --git a/scripts/Phalcon/Version/TimestampedItem.php b/scripts/Phalcon/Version/TimestampedItem.php index 8c4436a19..8fa435bf3 100644 --- a/scripts/Phalcon/Version/TimestampedItem.php +++ b/scripts/Phalcon/Version/TimestampedItem.php @@ -36,7 +36,7 @@ class TimestampedItem implements ItemInterface * @var string */ private $path; - + /** * @var string */ @@ -101,8 +101,7 @@ public function getDescription() /** * Set integer payload of the Path * - * @param $path - * @return integer + * @param string $path */ public function setPath($path) { @@ -113,7 +112,7 @@ public function setPath($path) /** * Get integer payload of the Path * - * @return integer + * @return string */ public function getPath() { From db198f9f4e8a3d621699edf6432cefc3af31e917 Mon Sep 17 00:00:00 2001 From: zcq <64899484@qq.com> Date: Wed, 24 Oct 2018 11:04:08 +0800 Subject: [PATCH 05/50] dosc: Optimization description --- scripts/Phalcon/Commands/Builtin/Migration.php | 2 +- scripts/Phalcon/Version/IncrementalItem.php | 4 ++-- scripts/Phalcon/Version/ItemInterface.php | 4 ++-- scripts/Phalcon/Version/TimestampedItem.php | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/Phalcon/Commands/Builtin/Migration.php b/scripts/Phalcon/Commands/Builtin/Migration.php index 4676c9afb..4494e888c 100644 --- a/scripts/Phalcon/Commands/Builtin/Migration.php +++ b/scripts/Phalcon/Commands/Builtin/Migration.php @@ -45,7 +45,7 @@ public function getPossibleParams() return [ 'action=s' => 'Generates a Migration [generate|run]', 'config=s' => 'Configuration file', - 'migrations=s' => 'Migrations directory,multiple dir use `,` separate', + 'migrations=s' => 'Migrations directory. Use comma separated string to specify multiple directories', 'directory=s' => 'Directory where the project was created', 'table=s' => 'Table to migrate. Table name or table prefix with asterisk. Default: all', 'version=s' => 'Version to migrate', diff --git a/scripts/Phalcon/Version/IncrementalItem.php b/scripts/Phalcon/Version/IncrementalItem.php index 036eae5b9..790459b45 100644 --- a/scripts/Phalcon/Version/IncrementalItem.php +++ b/scripts/Phalcon/Version/IncrementalItem.php @@ -222,7 +222,7 @@ public function getVersion() return $this->version; } /** - * Get integer payload of the Path + * Get migrations directory of incremental item * * @return string */ @@ -231,7 +231,7 @@ public function getPath() return $this->path; } /** - * Set integer payload of the Path + * Set migrations directory of incremental item * * @param string $path */ diff --git a/scripts/Phalcon/Version/ItemInterface.php b/scripts/Phalcon/Version/ItemInterface.php index 13a971e0e..21346f8c9 100644 --- a/scripts/Phalcon/Version/ItemInterface.php +++ b/scripts/Phalcon/Version/ItemInterface.php @@ -52,7 +52,7 @@ public function getVersion(); public function __toString(); /** - * Set integer payload of the Path + * Set migrations directory of incremental item * * @param string $path */ @@ -60,7 +60,7 @@ public function setPath($path); /** - * Get integer payload of the Path + * Get migrations directory of incremental item * * @return string */ diff --git a/scripts/Phalcon/Version/TimestampedItem.php b/scripts/Phalcon/Version/TimestampedItem.php index 8fa435bf3..0667232c3 100644 --- a/scripts/Phalcon/Version/TimestampedItem.php +++ b/scripts/Phalcon/Version/TimestampedItem.php @@ -99,7 +99,7 @@ public function getDescription() } /** - * Set integer payload of the Path + * Set migrations directory of incremental item * * @param string $path */ @@ -110,7 +110,7 @@ public function setPath($path) /** - * Get integer payload of the Path + * Get migrations directory of incremental item * * @return string */ From 97c5ca32a3677b785002b40e930491b99a93fe12 Mon Sep 17 00:00:00 2001 From: cq-z <64899484@qq.com> Date: Wed, 7 Nov 2018 19:18:09 +0800 Subject: [PATCH 06/50] Make provision to keep constant and properties when generating Views (#1253) --- phpstan.neon | 2 + scripts/Phalcon/Builder/Model.php | 105 +++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 2 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 69a1e63ab..334511db1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,3 +8,5 @@ parameters: - '#Call to an undefined method object::toArray().#' - '#supplied for foreach, only iterables are supported#' - '#Call to an undefined method [a-zA-Z0-9\\_]+::addMinor().#' + - '#Call to an undefined method ReflectionClass::getReflectionConstants\(\)\.#' + reportUnmatchedIgnoredErrors: false diff --git a/scripts/Phalcon/Builder/Model.php b/scripts/Phalcon/Builder/Model.php index 80c2434b1..3cc1c62cd 100644 --- a/scripts/Phalcon/Builder/Model.php +++ b/scripts/Phalcon/Builder/Model.php @@ -219,6 +219,7 @@ public function build() $alreadyFindFirst = false; $alreadyColumnMapped = false; $alreadyGetSourced = false; + $attributes = []; if (file_exists($modelPath)) { try { @@ -240,7 +241,7 @@ public function build() $linesCode = file($modelPath); $fullClassName = $this->modelOptions->getOption('className'); - if ($this->modelOptions->getOption('namespace')) { + if ($this->modelOptions->hasOption('namespace')) { $fullClassName = $this->modelOptions->getOption('namespace').'\\'.$fullClassName; } $reflection = new ReflectionClass($fullClassName); @@ -295,6 +296,107 @@ public function build() break; } } + + $possibleFields = []; + foreach ($fields as $field) { + $possibleFields[$field->getName()] = true; + } + if (method_exists($reflection, 'getReflectionConstants')) { + foreach ($reflection->getReflectionConstants() as $constant) { + if ($constant->getDeclaringClass()->getName() != $fullClassName) { + continue; + } + $constantsPreg = '/^(\s*)const(\s+)'.$constant->getName().'([\s=;]+)/'; + $endLine = $startLine = 0; + foreach ($linesCode as $line => $code) { + if (preg_match($constantsPreg, $code)) { + $startLine = $line; + break; + } + } + if (!empty($startLine)) { + $countLines = count($linesCode); + for ($i = $startLine; $i < $countLines; $i++) { + if (preg_match('/;(\s*)$/', $linesCode[$i])) { + $endLine = $i; + break; + } + } + } + + if (!empty($startLine) && !empty($endLine)) { + $constantDeclaration = join( + '', + array_slice( + $linesCode, + $startLine, + $endLine - $startLine + 1 + ) + ); + $attributes[] = PHP_EOL . " " . $constant->getDocComment() . + PHP_EOL . $constantDeclaration; + } + } + } + + foreach ($reflection->getProperties() as $propertie) { + $propertieName = $propertie->getName(); + + if ($propertie->getDeclaringClass()->getName() != $fullClassName || + !empty($possibleFields[$propertieName])) { + continue; + } + $modifiersPreg = ''; + switch ($propertie->getModifiers()) { + case \ReflectionProperty::IS_PUBLIC: + $modifiersPreg = '^(\s*)public(\s+)'; + break; + case \ReflectionProperty::IS_PRIVATE: + $modifiersPreg = '^(\s*)private(\s+)'; + break; + case \ReflectionProperty::IS_PROTECTED: + $modifiersPreg = '^(\s*)protected(\s+)'; + break; + case \ReflectionProperty::IS_STATIC + \ReflectionProperty::IS_PUBLIC: + $modifiersPreg = '^(\s*)(public?)(\s+)static(\s+)'; + break; + case \ReflectionProperty::IS_STATIC + \ReflectionProperty::IS_PROTECTED: + $modifiersPreg = '^(\s*)protected(\s+)static(\s+)'; + break; + case \ReflectionProperty::IS_STATIC + \ReflectionProperty::IS_PRIVATE: + $modifiersPreg = '^(\s*)private(\s+)static(\s+)'; + break; + } + $modifiersPreg = '/' . $modifiersPreg . '\$' . $propertieName . '([\s=;]+)/'; + $endLine = $startLine = 0; + foreach ($linesCode as $line => $code) { + if (preg_match($modifiersPreg, $code)) { + $startLine = $line; + break; + } + } + if (!empty($startLine)) { + $countLines = count($linesCode); + for ($i = $startLine; $i < $countLines; $i++) { + if (preg_match('/;(\s*)$/', $linesCode[$i])) { + $endLine = $i; + break; + } + } + } + if (!empty($startLine) && !empty($endLine)) { + $propertieDeclaration = join( + '', + array_slice( + $linesCode, + $startLine, + $endLine - $startLine + 1 + ) + ); + $attributes[] = PHP_EOL . " " . $propertie->getDocComment() . PHP_EOL . + $propertieDeclaration; + } + } } catch (\Exception $e) { throw new RuntimeException( sprintf( @@ -353,7 +455,6 @@ public function build() } } - $attributes = []; $setters = []; $getters = []; foreach ($fields as $field) { From c83c90cd49db0031a51c1e3c4248823f731db1bf Mon Sep 17 00:00:00 2001 From: montaccep <43525832+montaccep@users.noreply.github.com> Date: Mon, 12 Nov 2018 18:50:09 +0100 Subject: [PATCH 07/50] Updated Bootstrap framework to version 4.1.3 (#1257) --- templates/project/micro/views/404.phtml | 2 +- templates/project/micro/views/404.volt | 2 +- templates/project/micro/views/index.phtml | 10 +++++----- templates/project/micro/views/index.volt | 10 +++++----- templates/project/modules/views/index.phtml | 10 +++++----- templates/project/modules/views/index.volt | 10 +++++----- templates/project/simple/views/index.phtml | 10 +++++----- templates/project/simple/views/index.volt | 10 +++++----- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/templates/project/micro/views/404.phtml b/templates/project/micro/views/404.phtml index f4ba5e0de..00dfaf60e 100644 --- a/templates/project/micro/views/404.phtml +++ b/templates/project/micro/views/404.phtml @@ -1,7 +1,7 @@ - + Phalcon PHP Framework diff --git a/templates/project/micro/views/404.volt b/templates/project/micro/views/404.volt index 7e38e0a19..0978d3c0f 100644 --- a/templates/project/micro/views/404.volt +++ b/templates/project/micro/views/404.volt @@ -1,7 +1,7 @@ - + Phalcon PHP Framework diff --git a/templates/project/micro/views/index.phtml b/templates/project/micro/views/index.phtml index f998683a5..b5c7a9499 100644 --- a/templates/project/micro/views/index.phtml +++ b/templates/project/micro/views/index.phtml @@ -6,7 +6,7 @@ Phalcon PHP Framework - + @@ -20,9 +20,9 @@

This page is located at views/index.phtml

- - - - + + + + diff --git a/templates/project/micro/views/index.volt b/templates/project/micro/views/index.volt index 316678cbd..992b58bce 100644 --- a/templates/project/micro/views/index.volt +++ b/templates/project/micro/views/index.volt @@ -6,7 +6,7 @@ Phalcon PHP Framework - + @@ -21,9 +21,9 @@

This page is located at views/index.volt

- - - - + + + + diff --git a/templates/project/modules/views/index.phtml b/templates/project/modules/views/index.phtml index 95c0a44b0..cd415c367 100644 --- a/templates/project/modules/views/index.phtml +++ b/templates/project/modules/views/index.phtml @@ -6,16 +6,16 @@ Phalcon PHP Framework - +
getContent(); ?>
- - - - + + + + diff --git a/templates/project/modules/views/index.volt b/templates/project/modules/views/index.volt index b199a1014..6e769782d 100644 --- a/templates/project/modules/views/index.volt +++ b/templates/project/modules/views/index.volt @@ -6,16 +6,16 @@ Phalcon PHP Framework - +
{{ content() }}
- - - - + + + + diff --git a/templates/project/simple/views/index.phtml b/templates/project/simple/views/index.phtml index 95c0a44b0..cd415c367 100644 --- a/templates/project/simple/views/index.phtml +++ b/templates/project/simple/views/index.phtml @@ -6,16 +6,16 @@ Phalcon PHP Framework - +
getContent(); ?>
- - - - + + + + diff --git a/templates/project/simple/views/index.volt b/templates/project/simple/views/index.volt index b199a1014..6e769782d 100644 --- a/templates/project/simple/views/index.volt +++ b/templates/project/simple/views/index.volt @@ -6,16 +6,16 @@ Phalcon PHP Framework - +
{{ content() }}
- - - - + + + + From 229ea2ba5ce61776485b9cd4d482c2b0ccf04f70 Mon Sep 17 00:00:00 2001 From: Ciprian Coman Date: Tue, 25 Dec 2018 15:53:35 +0200 Subject: [PATCH 08/50] set database connection dialect (#1260) * set database connection dialect * consolidate if statement for Mysql --- scripts/Phalcon/Migrations.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/Phalcon/Migrations.php b/scripts/Phalcon/Migrations.php index 80b19f0b0..dcabda6d5 100644 --- a/scripts/Phalcon/Migrations.php +++ b/scripts/Phalcon/Migrations.php @@ -29,6 +29,8 @@ use Phalcon\Db\AdapterInterface; use Phalcon\Version\ItemInterface; use Phalcon\Script\ScriptException; +use Phalcon\Db\Dialect\DialectMysql; +use Phalcon\Db\Dialect\DialectPostgresql; use Phalcon\Db\Exception as DbException; use Phalcon\Mvc\Model\Exception as ModelException; use Phalcon\Mvc\Model\Migration as ModelMigration; @@ -471,9 +473,14 @@ private static function connectionSetup($options) self::$storage = new $adapter($configArray); if ($database->adapter === 'Mysql') { + self::$storage->setDialect(new DialectMysql); self::$storage->query('SET FOREIGN_KEY_CHECKS=0'); } + if ($database->adapter == 'Postgresql') { + self::$storage->setDialect(new DialectPostgresql); + } + if (!self::$storage->tableExists(self::MIGRATION_LOG_TABLE)) { self::$storage->createTable(self::MIGRATION_LOG_TABLE, null, [ 'columns' => [ From 2be9b3e10608c62a47b0086fca1d6669bb9553b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20B=C5=82aszczyk?= Date: Tue, 29 Jan 2019 02:13:29 +0100 Subject: [PATCH 09/50] Add new option to migration generate: exportDataFromTables (#1266) * 3.4.1 (#1261) * bugfix: webtools modelsNamespace typo * added: migration support multiple dir * fix: test file dir error * doc: PHPDoc error * dosc: Optimization description * Make provision to keep constant and properties when generating Views (#1253) * Updated Bootstrap framework to version 4.1.3 (#1257) * set database connection dialect (#1260) * set database connection dialect * consolidate if statement for Mysql * Add new parameter to migration generate: exportDataFromTables * docs improvement * fix line length * fix line length * fix line length * fix line length * fix line length * fix line length * rename variables * rename method * allow to pass exportDataFromTables from config:application * allow to pass exportDataFromTables from config:application as array --- .../Phalcon/Commands/Builtin/Migration.php | 12 ++++++++ scripts/Phalcon/Migrations.php | 14 +++++++-- scripts/Phalcon/Mvc/Model/Migration.php | 29 +++++++++++++------ 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/scripts/Phalcon/Commands/Builtin/Migration.php b/scripts/Phalcon/Commands/Builtin/Migration.php index 4494e888c..529b7c703 100644 --- a/scripts/Phalcon/Commands/Builtin/Migration.php +++ b/scripts/Phalcon/Commands/Builtin/Migration.php @@ -51,6 +51,7 @@ public function getPossibleParams() 'version=s' => 'Version to migrate', 'descr=s' => 'Migration description (used for timestamp based migration)', 'data=s' => 'Export data [always|oncreate] (Import data when run migration)', + 'exportDataFromTables=s' => 'Export data from specific tables, use comma separated string.', 'force' => 'Forces to overwrite existing migrations', 'ts-based' => 'Timestamp based migration version', 'log-in-db' => 'Keep migrations log in the database table rather than in file', @@ -79,6 +80,16 @@ public function run(array $parameters) $config = $this->getConfig($path); } + $exportDataFromTables= []; + if ($this->isReceivedOption('exportDataFromTables')) { + $exportDataFromTables = explode(',', $this->getOption('exportDataFromTables')); + } elseif (isset($config['application']['exportDataFromTables'])) { + if ($config['application']['exportDataFromTables'] instanceof Config) { + $exportDataFromTables = $config['application']['exportDataFromTables']->toArray(); + } else { + $exportDataFromTables = explode(',', $config['application']['exportDataFromTables']); + } + } //multiple dir $migrationsDir = []; @@ -131,6 +142,7 @@ public function run(array $parameters) 'directory' => $path, 'tableName' => $tableName, 'exportData' => $this->getOption('data'), + 'exportDataFromTables' => $exportDataFromTables, 'migrationsDir' => $migrationsDir, 'version' => $this->getOption('version'), 'force' => $this->isReceivedOption('force'), diff --git a/scripts/Phalcon/Migrations.php b/scripts/Phalcon/Migrations.php index dcabda6d5..7d894762a 100644 --- a/scripts/Phalcon/Migrations.php +++ b/scripts/Phalcon/Migrations.php @@ -138,7 +138,11 @@ public static function generate(array $options) $wasMigrated = false; if ($optionStack->getOption('tableName') === '@') { - $migrations = ModelMigration::generateAll($versionItem, $optionStack->getOption('exportData')); + $migrations = ModelMigration::generateAll( + $versionItem, + $optionStack->getOption('exportData'), + $optionStack->getOption('exportDataFromTables') + ); if (!$optionStack->getOption('verbose')) { foreach ($migrations as $tableName => $migration) { if ($tableName === self::MIGRATION_LOG_TABLE) { @@ -164,7 +168,12 @@ public static function generate(array $options) $tables = explode(',', $optionStack->getOption('tableName')); foreach ($tables as $table) { - $migration = ModelMigration::generate($versionItem, $table, $optionStack->getOption('exportData')); + $migration = ModelMigration::generate( + $versionItem, + $table, + $optionStack->getOption('exportData'), + $optionStack->getOption('exportDataFromTables') + ); if (!$optionStack->getOption('verbose')) { $tableFile = $migrationPath . DIRECTORY_SEPARATOR . $table . '.php'; $wasMigrated = file_put_contents( @@ -295,7 +304,6 @@ public static function run(array $options) if ($initialVersion->getVersion() == $versionItem->getVersion()) { $initialVersion->setPath($versionItem->getPath()); } - // If we are rolling back, we skip migrating when initialVersion is the same as current if ($initialVersion->getVersion() === $versionItem->getVersion() && ModelMigration::DIRECTION_BACK === $direction) { diff --git a/scripts/Phalcon/Mvc/Model/Migration.php b/scripts/Phalcon/Mvc/Model/Migration.php index 025ca541b..214b50da5 100644 --- a/scripts/Phalcon/Mvc/Model/Migration.php +++ b/scripts/Phalcon/Mvc/Model/Migration.php @@ -178,13 +178,13 @@ public static function setMigrationPath($path) * * @return array */ - public static function generateAll(ItemInterface $version, $exportData = null) + public static function generateAll(ItemInterface $version, $exportData = null, $exportDataFromTables = null) { $classDefinition = []; $schema = Utils::resolveDbSchema(self::$databaseConfig); foreach (self::$connection->listTables($schema) as $table) { - $classDefinition[$table] = self::generate($version, $table, $exportData); + $classDefinition[$table] = self::generate($version, $table, $exportData, $exportDataFromTables); } return $classDefinition; @@ -200,6 +200,11 @@ public static function getDbName() return self::$databaseConfig->get('dbname'); } + public static function shouldExportDataFromTable($table, $exportDataFromTables) + { + return in_array($table, $exportDataFromTables); + } + /** * Generate specified table migration * @@ -210,8 +215,12 @@ public static function getDbName() * @return string * @throws \Phalcon\Db\Exception */ - public static function generate(ItemInterface $version, $table, $exportData = null) - { + public static function generate( + ItemInterface $version, + $table, + $exportData = null, + $exportDataFromTables = null + ) { $oldColumn = null; $allFields = []; $numericFields = []; @@ -290,7 +299,7 @@ public static function generate(ItemInterface $version, $table, $exportData = nu $fieldDefinition[] = "'default' => \"$default\""; } //if ($field->isPrimary()) { - //$fieldDefinition[] = "'primary' => true"; + //$fieldDefinition[] = "'primary' => true"; //} if ($field->isUnsigned()) { @@ -399,7 +408,7 @@ public static function generate(ItemInterface $version, $table, $exportData = nu // up() $classData .= $snippet->getMigrationUp(); - if ($exportData == 'always') { + if ($exportData == 'always' || self::shouldExportDataFromTable($table, $exportDataFromTables)) { $classData .= $snippet->getMigrationBatchInsert($table, $allFields); } @@ -408,14 +417,14 @@ public static function generate(ItemInterface $version, $table, $exportData = nu // down() $classData .= $snippet->getMigrationDown(); - if ($exportData == 'always') { + if ($exportData == 'always' || self::shouldExportDataFromTable($table, $exportDataFromTables)) { $classData .= $snippet->getMigrationBatchDelete($table); } $classData .= "\n }\n"; // afterCreateTable() - if ($exportData == 'oncreate') { + if ($exportData == 'oncreate' || self::shouldExportDataFromTable($table, $exportDataFromTables)) { $classData .= $snippet->getMigrationAfterCreateTable($table, $allFields); } @@ -423,7 +432,9 @@ public static function generate(ItemInterface $version, $table, $exportData = nu $classData .= "\n}\n"; // dump data - if ($exportData == 'always' || $exportData == 'oncreate') { + if ($exportData == 'always' || + $exportData == 'oncreate' || + self::shouldExportDataFromTable($table, $exportDataFromTables)) { $fileHandler = fopen(self::$migrationPath . $version->getVersion() . '/' . $table . '.dat', 'w'); $cursor = self::$connection->query('SELECT * FROM '. self::$connection->escapeIdentifier($table)); $cursor->setFetchMode(Db::FETCH_ASSOC); From 6dc2543c5a48006975d5620658bb9a7358d988da Mon Sep 17 00:00:00 2001 From: Mike Glenn Date: Tue, 29 Jan 2019 20:05:26 +0000 Subject: [PATCH 10/50] fix issue #1256 --- templates/project/modules/bootstrap_web.php | 2 +- templates/project/simple/index.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/project/modules/bootstrap_web.php b/templates/project/modules/bootstrap_web.php index 83b66ac5b..34387bfd4 100644 --- a/templates/project/modules/bootstrap_web.php +++ b/templates/project/modules/bootstrap_web.php @@ -53,7 +53,7 @@ */ require APP_PATH . '/config/routes.php'; - echo str_replace(["\n","\r","\t"], '', $application->handle()->getContent()); + echo $application->handle()->getContent(); } catch (\Exception $e) { echo $e->getMessage() . '
'; diff --git a/templates/project/simple/index.php b/templates/project/simple/index.php index ed1037caa..a3ccb682f 100644 --- a/templates/project/simple/index.php +++ b/templates/project/simple/index.php @@ -39,7 +39,7 @@ */ $application = new \Phalcon\Mvc\Application($di); - echo str_replace(["\n","\r","\t"], '', $application->handle()->getContent()); + echo $application->handle()->getContent(); } catch (\Exception $e) { echo $e->getMessage() . '
'; From a2e949976a3ba88254a4abb81c3ff75d8a445c08 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 8 Mar 2019 17:21:51 +0000 Subject: [PATCH 11/50] #1249 - Removed class .row in .center-block --- scripts/Phalcon/Builder/Scaffold.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/Phalcon/Builder/Scaffold.php b/scripts/Phalcon/Builder/Scaffold.php index 233a095fc..cb421b7b6 100644 --- a/scripts/Phalcon/Builder/Scaffold.php +++ b/scripts/Phalcon/Builder/Scaffold.php @@ -602,7 +602,7 @@ private function makeLayouts() $code .= 'tag->stylesheetLink("themes/base") ?>'.PHP_EOL; $code .= '
' . PHP_EOL; } else { - $code .= '
' . PHP_EOL; + $code .= '
' . PHP_EOL; } $code .= "\t" . 'getContent(); ?>' . PHP_EOL . '
'; @@ -642,7 +642,7 @@ private function makeLayoutsVolt() $code .= '{{ stylesheet_link("themes/base") }}'.PHP_EOL; $code .= '
' . PHP_EOL; } else { - $code .= '
' . PHP_EOL; + $code .= '
' . PHP_EOL; } $code .= "\t" . '{{ content() }}' . PHP_EOL . '
'; From b873619c95d32f9a26fef53365d955568e6b2162 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 8 Mar 2019 17:44:11 +0000 Subject: [PATCH 12/50] #1249 - Fixed pagination links in scaffold/no-forms/views/search.phtml --- templates/scaffold/no-forms/views/search.phtml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/scaffold/no-forms/views/search.phtml b/templates/scaffold/no-forms/views/search.phtml index 6588a1c4f..36c93625b 100644 --- a/templates/scaffold/no-forms/views/search.phtml +++ b/templates/scaffold/no-forms/views/search.phtml @@ -51,10 +51,10 @@
From 50cfaeffd0d038101b68bd4d167d757c887c2049 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 11 Mar 2019 09:38:02 +0000 Subject: [PATCH 13/50] #1249 - Fixed pagination links in scaffold/no-forms/views/search.volt --- templates/scaffold/no-forms/views/search.volt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/scaffold/no-forms/views/search.volt b/templates/scaffold/no-forms/views/search.volt index ee5ab1158..34693d90d 100644 --- a/templates/scaffold/no-forms/views/search.volt +++ b/templates/scaffold/no-forms/views/search.volt @@ -45,10 +45,10 @@
From 640d2bead2bf1531545c2dd8c7540d80f1b53b31 Mon Sep 17 00:00:00 2001 From: Kevin Yarmak Date: Wed, 6 Mar 2019 05:13:11 -0800 Subject: [PATCH 14/50] Fixing phalcon serve on newer PHP versions - issue #1233 --- scripts/Phalcon/Commands/Builtin/Serve.php | 4 ++-- tests/unit/ServeTest.php | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/Phalcon/Commands/Builtin/Serve.php b/scripts/Phalcon/Commands/Builtin/Serve.php index cad56456d..db88d8b58 100644 --- a/scripts/Phalcon/Commands/Builtin/Serve.php +++ b/scripts/Phalcon/Commands/Builtin/Serve.php @@ -127,12 +127,12 @@ public function shellCommand() $this->printServerDetails(); return sprintf( - '%s -S %s:%s -t %s %s %s', + '%s -S %s:%s -t %s -t %s %s', $binary_path, $this->hostname, $this->port, - $this->document_root, $this->base_path, + $this->document_root, $this->config ); } diff --git a/tests/unit/ServeTest.php b/tests/unit/ServeTest.php index 098dc2461..76e4f0ce8 100644 --- a/tests/unit/ServeTest.php +++ b/tests/unit/ServeTest.php @@ -69,7 +69,7 @@ public function testGeneratedCommandWithNoParameters() $_SERVER['argv'] = ['','']; $this->command->parseParameters([], []); $command = $this->command->shellCommand(); - $this->assertContains('php -S 0.0.0.0:8000 -t public .htrouter.php', $command); + $this->assertContains('php -S 0.0.0.0:8000 -t .htrouter.php -t public', $command); } /** @@ -103,7 +103,7 @@ public function testGeneratedCommandWithHostnameOnly() $_SERVER['argv'] = ['','', 'localhost']; $this->command->parseParameters([], []); $command = $this->command->shellCommand(); - $this->assertContains('php -S localhost:8000 -t public .htrouter.php', $command); + $this->assertContains('php -S localhost:8000 -t .htrouter.php -t public', $command); } /** @@ -137,7 +137,7 @@ public function testGeneratedCommandWithPortOnly() $_SERVER['argv'] = ['','', null, 1111]; $this->command->parseParameters([], []); $command = $this->command->shellCommand(); - $this->assertContains('php -S 0.0.0.0:1111 -t public .htrouter.php', $command); + $this->assertContains('php -S 0.0.0.0:1111 -t .htrouter.php -t public', $command); } /** @@ -171,7 +171,7 @@ public function testGeneratedCommandWithBasepathOnly() $_SERVER['argv'] = ['','', null, null, '/root/bin.php']; $this->command->parseParameters([], []); $command = $this->command->shellCommand(); - $this->assertContains('php -S 0.0.0.0:8000 -t public /root/bin.php', $command); + $this->assertContains('php -S 0.0.0.0:8000 -t /root/bin.php -t public', $command); } /** @@ -205,7 +205,7 @@ public function testGeneratedCommandWithDocumentRootOnly() $_SERVER['argv'] = ['','', null, null, null, 'not_too_public']; $this->command->parseParameters([], []); $command = $this->command->shellCommand(); - $this->assertContains('php -S 0.0.0.0:8000 -t not_too_public .htrouter.php', $command); + $this->assertContains('php -S 0.0.0.0:8000 -t .htrouter.php -t not_too_public', $command); } /** @@ -239,6 +239,6 @@ public function testGeneratedCommandWithConfigOnly() $_SERVER['argv'] = ['','', null, null, null, '--config=awesome.ini']; $this->command->parseParameters([], []); $command = $this->command->shellCommand(); - $this->assertContains('php -S 0.0.0.0:8000 -t public .htrouter.php -c awesome.ini', $command); + $this->assertContains('php -S 0.0.0.0:8000 -t .htrouter.php -t public -c awesome.ini', $command); } } From 2fffd9a63c1d7cb189b2aadb6ed13b6134b4e09e Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 15 Mar 2019 16:53:28 +0000 Subject: [PATCH 15/50] #1277 - Changed CPHALCON_DIR from constant to environment variable --- ide/gen-stubs.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ide/gen-stubs.php b/ide/gen-stubs.php index 6d9d10b02..6d2cbc395 100644 --- a/ide/gen-stubs.php +++ b/ide/gen-stubs.php @@ -3,18 +3,17 @@ /** * This scripts generates the stubs to be used on IDEs * - * Change the CPHALCON_DIR constant to point to the dev/ directory in the Phalcon source code + * Specify CPHALCON_DIR env variable to point to the dev/ directory in the Phalcon source code * - * php ide/gen-stubs.php + * *nix: CPHALCON_DIR=/path/to/cphalcon/ext/ php ide/gen-stubs.php + * Win: set CPHALCON_DIR=C:\Path\To\cphalcon\ext\ php ide/gen-stubs.php */ if (!extension_loaded('phalcon')) { throw new Exception("phalcon extension isn't installed"); } -define('CPHALCON_DIR' , '/Users/micate/Code/cphalcon/ext/'); - -if (!file_exists(CPHALCON_DIR)) { +if (getenv('CPHALCON_DIR') === false || !file_exists(getenv('CPHALCON_DIR'))) { throw new Exception("CPHALCON directory does not exist"); } @@ -123,7 +122,7 @@ public function getClassDocs() $versionPieces = explode(' ', $version); $genVersion = $versionPieces[0]; -$api = new Stubs_Generator(CPHALCON_DIR); +$api = new Stubs_Generator(getenv('CPHALCON_DIR')); $classDocs = $api->getClassDocs(); $docs = $api->getDocs(); From e01f04f7c93dd9636ce1a72136c7ace62331e66c Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 15 Mar 2019 22:08:34 +0000 Subject: [PATCH 16/50] Added deprecated for gen-stubs.php --- ide/gen-stubs.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ide/gen-stubs.php b/ide/gen-stubs.php index 6d2cbc395..11170de9a 100644 --- a/ide/gen-stubs.php +++ b/ide/gen-stubs.php @@ -7,6 +7,11 @@ * * *nix: CPHALCON_DIR=/path/to/cphalcon/ext/ php ide/gen-stubs.php * Win: set CPHALCON_DIR=C:\Path\To\cphalcon\ext\ php ide/gen-stubs.php + * + * Alternative stubs generation + * + * cd cphalcon + * zephir stubs */ if (!extension_loaded('phalcon')) { @@ -17,6 +22,11 @@ throw new Exception("CPHALCON directory does not exist"); } +/** + * Class Stubs_Generator + * + * @deprecated In version 4.x current class will be removed + */ class Stubs_Generator { From b463d762c37e8500d3ff9a9b1498d6e4acc2e3d4 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 16 Mar 2019 10:04:47 +0000 Subject: [PATCH 17/50] #1277 - Added separate exception if CPHALCON_DIR is not specified --- ide/gen-stubs.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ide/gen-stubs.php b/ide/gen-stubs.php index 11170de9a..ea96ae3f8 100644 --- a/ide/gen-stubs.php +++ b/ide/gen-stubs.php @@ -18,7 +18,21 @@ throw new Exception("phalcon extension isn't installed"); } -if (getenv('CPHALCON_DIR') === false || !file_exists(getenv('CPHALCON_DIR'))) { +if (getenv('CPHALCON_DIR') === false) { + throw new Exception(<< Date: Sat, 16 Mar 2019 17:13:10 +0000 Subject: [PATCH 18/50] #1238 - Removed phalcon.bat --- phalcon.bat | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 phalcon.bat diff --git a/phalcon.bat b/phalcon.bat deleted file mode 100644 index 810bea040..000000000 --- a/phalcon.bat +++ /dev/null @@ -1,4 +0,0 @@ -@echo off - -set PTOOLSPATH=%~dp0 -php %PTOOLSPATH%phalcon.php %* \ No newline at end of file From 766e39b10136233ba2f4243f804c8f77c3f6d741 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 16 Mar 2019 17:13:35 +0000 Subject: [PATCH 19/50] #1238 - Rename phalcon.php -> phalcon --- phalcon.php => phalcon | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename phalcon.php => phalcon (100%) mode change 100755 => 100644 diff --git a/phalcon.php b/phalcon old mode 100755 new mode 100644 similarity index 100% rename from phalcon.php rename to phalcon From b5c1b1856f0a0b78f5d7602b92e3f9377635bb3e Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 16 Mar 2019 17:14:22 +0000 Subject: [PATCH 20/50] #1238 - Changed bin filename in composer.json from phalcon.php to phalcon --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1c09a7cbc..2bee3089c 100644 --- a/composer.json +++ b/composer.json @@ -52,5 +52,5 @@ "tests/_support/helpers.php" ] }, - "bin": ["phalcon.php"] + "bin": ["phalcon"] } From d014638016a86ef1207779853a3c905a0a60e3d1 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 16 Mar 2019 17:25:45 +0000 Subject: [PATCH 21/50] #1238 - Fixed before_script in .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6071b81f6..da9fc7d07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,7 +60,7 @@ install: - if [ "$PHP_MAJOR" == "7" ]; then composer require --dev phpstan/phpstan:^0.9; fi; before_script: - - ln -s $PWD/phalcon.php ~/bin/phalcon + - ln -s $PWD/phalcon ~/bin/phalcon script: - vendor/bin/phpcs From e090653864db1c916d46b6a976cf5bafd290ae59 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 16 Mar 2019 22:20:15 +0000 Subject: [PATCH 22/50] #1238 - Fixed chmod to 755 for phalcon file --- phalcon | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 phalcon diff --git a/phalcon b/phalcon old mode 100644 new mode 100755 From 0e72a8c43c2d92389b5700e826fb4fd0d2df183e Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 16 Mar 2019 22:49:05 +0000 Subject: [PATCH 23/50] #1238 - Fixed box.json for building phalcon.phar --- box.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/box.json b/box.json index 03a8acea8..511cc50cd 100644 --- a/box.json +++ b/box.json @@ -1,5 +1,5 @@ { - "main": "phalcon.php", + "main": "phalcon", "output": "phalcon.phar", "chmod": "0755", "directories": [ From c3059f0d22e93e56707164dd21051a0d874a83be Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sat, 16 Mar 2019 22:49:50 +0000 Subject: [PATCH 24/50] #1238 - Mass rename in files phalcon.php -> phalcon --- README.md | 6 +++--- ide/phpstorm/phalcon.bat | 2 +- ide/phpstorm/phalcon.sh | 2 +- phalcon.sh | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8a2534932..571045b32 100644 --- a/README.md +++ b/README.md @@ -86,19 +86,19 @@ cd phalcon-devtools ``` This method requires a little bit more of setup. Probably the best way would be to symlink -the `phalcon.php` to a directory in your `PATH`, so you can issue phalcon commands in each directory +the `phalcon` file to a directory in your `PATH`, so you can issue phalcon commands in each directory where a phalcon project resides. ```bash cd phalcon-devtools -ln -s $(pwd)/phalcon.php /usr/bin/phalcon +ln -s $(pwd)/phalcon /usr/bin/phalcon chmod ugo+x /usr/bin/phalcon ``` If you get a `"phalcon: command not found"` message while creating the symlink, make an alias. ```bash -alias phalcon=/home/[USERNAME]/phalcon-devtools/phalcon.php +alias phalcon=/home/[USERNAME]/phalcon-devtools/phalcon ``` ## Usage diff --git a/ide/phpstorm/phalcon.bat b/ide/phpstorm/phalcon.bat index 1bc92c0d9..147755354 100644 --- a/ide/phpstorm/phalcon.bat +++ b/ide/phpstorm/phalcon.bat @@ -1,4 +1,4 @@ @echo off set PTOOLSPATH=. -php %PTOOLSPATH%\phalcon.php %* +php %PTOOLSPATH%\phalcon %* diff --git a/ide/phpstorm/phalcon.sh b/ide/phpstorm/phalcon.sh index 1fc397a4e..2bd48493b 100755 --- a/ide/phpstorm/phalcon.sh +++ b/ide/phpstorm/phalcon.sh @@ -37,7 +37,7 @@ if [ -z "$PTOOLSPATH" ]; then fi if [ ! -z "$PTOOLSPATH" ]; then - php "$PTOOLSPATH/phalcon.php" $* + php "$PTOOLSPATH/phalcon" $* else if [ -n "$ZSH_VERSION" ]; then echo "Error: Add environment variable PTOOLSPATH to your $HOME/.zsh" diff --git a/phalcon.sh b/phalcon.sh index 6b3ae1fca..34eb1d727 100755 --- a/phalcon.sh +++ b/phalcon.sh @@ -96,7 +96,7 @@ check_install(){ if [ -z "$PTOOLSPATH" ]; then printf "\n${YELLOW}Phalcon Developer Tools Installer${NC}" printf "\n" - printf "\n${PURPLE}Make sure phalcon.sh is in the same dir as phalcon.php${NC}" + printf "\n${PURPLE}Make sure phalcon.sh is in the same dir as phalcon file${NC}" printf "\n${PURPLE}and that you are running this with sudo or as root.${NC}" printf "\n" printf "\nInstalling Devtools..." @@ -147,5 +147,5 @@ init if check_install; then devtools=${PTOOLSPATH%/} - php "$devtools/phalcon.php" $* + php "$devtools/phalcon" $* fi From 3628136072f60512bb1ff97875ac1039efc08bd8 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 18 Mar 2019 10:48:23 +0000 Subject: [PATCH 25/50] #1284 - Updated requirements of PHP in composer --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2bee3089c..62f975ade 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "forum": "https://forum.phalconphp.com/" }, "require": { - "php": ">=5.5", + "php": ">=5.5 < 7.3.2 || >7.3.3", "ext-phalcon": "~3.3", "psy/psysh": "~0.9", "nikic/php-parser": "^3.1" From 51b9328c805dfb4c903785cda5ad2df0ea324548 Mon Sep 17 00:00:00 2001 From: talal424 Date: Tue, 19 Mar 2019 15:35:43 +0300 Subject: [PATCH 26/50] fixes for issue #1235 and issue #1286 all issues are in file: ```scripts/Phalcon/Builder/Model.php``` * bugfix: fixes issue #1235 this issue occurs when creating model without using namespace it throws InvalidArgumentException when setting relations ```hasMany``` and ```belongsTo``` * bugfix: fixes issue #1286 this issue is when creating model without using namespace the ```Model::getEntityClassName``` method produces extra backslash only in belongsTo relation example: ```php $this->belongsTo('school_year_id', '\SchoolYear', 'school_year_id', ['alias' => 'SchoolYear']); ``` **In raising this pull request, I confirm the following (please check boxes):** - [X] I have read and understood the [Contributing Guidelines][:contrib:] - [X] I have checked that another pull request for this purpose does not exist - [ ] I wrote some tests for this PR Small description of change: changes to ```line #183``` and ```line #201``` changed ```getOption``` method to ```hasOption``` changes to ``` line #202``` and ``` line #210``` backslash added only if namespace used Thanks --- scripts/Phalcon/Builder/Model.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/Phalcon/Builder/Model.php b/scripts/Phalcon/Builder/Model.php index 3cc1c62cd..749601ce5 100644 --- a/scripts/Phalcon/Builder/Model.php +++ b/scripts/Phalcon/Builder/Model.php @@ -180,7 +180,7 @@ public function build() } $entityNamespace = ''; - if ($this->modelOptions->getOption('namespace')) { + if ($this->modelOptions->hasOption('namespace')) { $entityNamespace = $this->modelOptions->getOption('namespace')."\\"; } @@ -198,8 +198,8 @@ public function build() foreach ($db->describeReferences($this->modelOptions->getOption('name'), $schema) as $reference) { $entityNamespace = ''; - if ($this->modelOptions->getOption('namespace')) { - $entityNamespace = $this->modelOptions->getOption('namespace'); + if ($this->modelOptions->hasOption('namespace')) { + $entityNamespace = $this->modelOptions->getOption('namespace')."\\"; } $refColumns = $reference->getReferencedColumns(); @@ -207,7 +207,7 @@ public function build() $initialize[] = $snippet->getRelation( 'belongsTo', $this->modelOptions->getOption('camelize') ? Utils::lowerCamelize($columns[0]) : $columns[0], - $this->getEntityClassName($reference, $entityNamespace), + $entityNamespace . Utils::camelize($reference->getReferencedTable()), $this->modelOptions->getOption('camelize') ? Utils::lowerCamelize($refColumns[0]) : $refColumns[0], "['alias' => '" . Text::camelize($reference->getReferencedTable(), '_-') . "']" ); From 810a0374a8e78abbaffcebebc87c9499ca274bb6 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 22 Mar 2019 09:31:23 +0000 Subject: [PATCH 27/50] #1288 - Updated Phalcon Docs link href --- resources/elements/sidebar-menu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/elements/sidebar-menu.php b/resources/elements/sidebar-menu.php index c9c16ff19..48c287fb7 100644 --- a/resources/elements/sidebar-menu.php +++ b/resources/elements/sidebar-menu.php @@ -192,7 +192,7 @@ // Phalcon Docs [ 'link' => [ - 'href' => 'https://docs.phalconphp.com/en/3.2', + 'href' => 'https://docs.phalconphp.com/3.4/en/', 'icon' => 'fa fa-book', 'local' => false, 'target' => '_blank', From 40da2beaf1b613d6ba0533878dbf76fc584c8504 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 22 Mar 2019 09:34:56 +0000 Subject: [PATCH 28/50] #1288 - Added Phalcon Discord Server link to sidebar menu --- resources/elements/sidebar-menu.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/resources/elements/sidebar-menu.php b/resources/elements/sidebar-menu.php index 48c287fb7..a400706db 100644 --- a/resources/elements/sidebar-menu.php +++ b/resources/elements/sidebar-menu.php @@ -224,5 +224,17 @@ 'wrap' => 'span', ], ], + + // Phalcon Discord Server + [ + 'link' => [ + 'href' => 'https://phalcon.link/discord', + 'icon' => 'fa fa-discord', + 'local' => false, + 'target' => '_blank', + 'text' => 'Discord Server', + 'wrap' => 'span', + ] + ] ], ]; From d23c2f641797eb0081c6522b43b13df4c7694242 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 22 Mar 2019 09:39:02 +0000 Subject: [PATCH 29/50] #1288 - Added Phalcon Forum link to sidebar menu --- resources/elements/sidebar-menu.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/resources/elements/sidebar-menu.php b/resources/elements/sidebar-menu.php index a400706db..6003e7ec3 100644 --- a/resources/elements/sidebar-menu.php +++ b/resources/elements/sidebar-menu.php @@ -225,6 +225,18 @@ ], ], + // Phalcon Official Forum + [ + 'link' => [ + 'href' => 'https://forum.phalconphp.com/', + 'icon' => 'fa fa-comment-alt', + 'local' => false, + 'target' => '_blank', + 'text' => 'Phalcon Forum', + 'wrap' => 'span', + ], + ], + // Phalcon Discord Server [ 'link' => [ From ae43d7e9d77f0d2ea269b92ca6b85a663d68cddf Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 22 Mar 2019 09:41:03 +0000 Subject: [PATCH 30/50] #1288 - Fixed font awesome icons --- resources/elements/sidebar-menu.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/elements/sidebar-menu.php b/resources/elements/sidebar-menu.php index 6003e7ec3..484b04e1c 100644 --- a/resources/elements/sidebar-menu.php +++ b/resources/elements/sidebar-menu.php @@ -229,7 +229,7 @@ [ 'link' => [ 'href' => 'https://forum.phalconphp.com/', - 'icon' => 'fa fa-comment-alt', + 'icon' => 'fa fa-comment-o', 'local' => false, 'target' => '_blank', 'text' => 'Phalcon Forum', @@ -241,7 +241,7 @@ [ 'link' => [ 'href' => 'https://phalcon.link/discord', - 'icon' => 'fa fa-discord', + 'icon' => 'fa fa-comments', 'local' => false, 'target' => '_blank', 'text' => 'Discord Server', From 8fe8dfe0a35a1da08855e8488ec7018250267746 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 22 Mar 2019 14:14:22 +0000 Subject: [PATCH 31/50] #1288 - Changed href of Phalcon Official Forum --- resources/elements/sidebar-menu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/elements/sidebar-menu.php b/resources/elements/sidebar-menu.php index 484b04e1c..d2e10b859 100644 --- a/resources/elements/sidebar-menu.php +++ b/resources/elements/sidebar-menu.php @@ -228,7 +228,7 @@ // Phalcon Official Forum [ 'link' => [ - 'href' => 'https://forum.phalconphp.com/', + 'href' => 'https://phalcon.link/forum', 'icon' => 'fa fa-comment-o', 'local' => false, 'target' => '_blank', From c90405bdb9e16c8f82393563c17287ba0cacb85c Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 22 Mar 2019 15:41:12 +0000 Subject: [PATCH 32/50] #1288 - Changed href of Phalcon Docs --- resources/elements/sidebar-menu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/elements/sidebar-menu.php b/resources/elements/sidebar-menu.php index d2e10b859..11a996363 100644 --- a/resources/elements/sidebar-menu.php +++ b/resources/elements/sidebar-menu.php @@ -192,7 +192,7 @@ // Phalcon Docs [ 'link' => [ - 'href' => 'https://docs.phalconphp.com/3.4/en/', + 'href' => 'https://phalcon.link/docs', 'icon' => 'fa fa-book', 'local' => false, 'target' => '_blank', From 7d07de2e131387ca19265b5cfd13c6932c62d836 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 2 Apr 2019 15:54:46 +0100 Subject: [PATCH 33/50] #1234 - Added config option to model builder --- scripts/Phalcon/Web/Tools/Controllers/ModelsController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/Phalcon/Web/Tools/Controllers/ModelsController.php b/scripts/Phalcon/Web/Tools/Controllers/ModelsController.php index 2ac303404..10526e5c0 100644 --- a/scripts/Phalcon/Web/Tools/Controllers/ModelsController.php +++ b/scripts/Phalcon/Web/Tools/Controllers/ModelsController.php @@ -235,7 +235,8 @@ public function generateAction() 'genSettersGetters' => $this->request->getPost('genSettersGetters', 'int'), 'namespace' => $this->request->getPost('namespace', 'string'), 'schema' => $this->request->getPost('schema', 'string'), - 'mapColumn' => $this->request->getPost('mapcolumn', 'int') + 'mapColumn' => $this->request->getPost('mapcolumn', 'int'), + 'config' => $this->config, ]); $modelBuilder->build(); From 23363410580a41e857ed67718747815d664a6775 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 2 Apr 2019 16:27:47 +0100 Subject: [PATCH 34/50] #1190 - Decreased column size of MIGRATION_LOG_TABLE.version from 255 to 190 --- scripts/Phalcon/Migrations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Phalcon/Migrations.php b/scripts/Phalcon/Migrations.php index 7d894762a..41ac96025 100644 --- a/scripts/Phalcon/Migrations.php +++ b/scripts/Phalcon/Migrations.php @@ -496,7 +496,7 @@ private static function connectionSetup($options) 'version', [ 'type' => Column::TYPE_VARCHAR, - 'size' => 255, + 'size' => 190, // utf8: 255*3 = 765 bytes, utf8mb4: 255*4 = 1020 bytes 'notNull' => true, ] ), From 389bc4ca830e04b15de33c98f5906ead58fcbaca Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Wed, 3 Apr 2019 09:28:53 +0100 Subject: [PATCH 35/50] #1290 - Added comment for PTOOLS_IP --- templates/webtools.config.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/webtools.config.php b/templates/webtools.config.php index 82ad724e4..f0b9fb416 100644 --- a/templates/webtools.config.php +++ b/templates/webtools.config.php @@ -26,6 +26,8 @@ * * For example: * 192.168.0.1 or SUBNET 192., 10.0.2., 86.84.124. + * For docker or dynamic IPs: + * $_SERVER['REMOTE_ADDR'] */ defined('PTOOLS_IP') || define('PTOOLS_IP', '192.168.'); defined('BASE_PATH') || define('BASE_PATH', dirname(dirname(__FILE__))); From 2ecb5364f050727a564cba239d6e5153c82ae29b Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Wed, 3 Apr 2019 09:39:57 +0100 Subject: [PATCH 36/50] #1264 - Code cleanup --- scripts/Phalcon/Mvc/Model/Migration.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/Phalcon/Mvc/Model/Migration.php b/scripts/Phalcon/Mvc/Model/Migration.php index 214b50da5..afbc9fb74 100644 --- a/scripts/Phalcon/Mvc/Model/Migration.php +++ b/scripts/Phalcon/Mvc/Model/Migration.php @@ -298,9 +298,6 @@ public static function generate( $default = $field->getDefault(); $fieldDefinition[] = "'default' => \"$default\""; } - //if ($field->isPrimary()) { - //$fieldDefinition[] = "'primary' => true"; - //} if ($field->isUnsigned()) { $fieldDefinition[] = "'unsigned' => true"; From 362f7a85005d8040b07a01bbdac34a984fc15e67 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Wed, 3 Apr 2019 09:51:13 +0100 Subject: [PATCH 37/50] #1264 - Added new static method Migration::columnHasSize() --- scripts/Phalcon/Mvc/Model/Migration.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/Phalcon/Mvc/Model/Migration.php b/scripts/Phalcon/Mvc/Model/Migration.php index afbc9fb74..a74179f06 100644 --- a/scripts/Phalcon/Mvc/Model/Migration.php +++ b/scripts/Phalcon/Mvc/Model/Migration.php @@ -928,4 +928,25 @@ public function getConnection() { return self::$connection; } + + /** + * Determine if column has size + * + * @param string $type + * @return bool + */ + public static function columnHasSize($type) + { + $adapter = self::$databaseConfig->path('adapter'); + if ($adapter == 'Postgresql' && + in_array($type, [Column::TYPE_BOOLEAN, Column::TYPE_INTEGER, Column::TYPE_BIGINTEGER])) { + return false; + } + + if ($type == Column::TYPE_TEXT) { + return false; + } + + return true; + } } From 6d6b197a37f6f0f03ecdb3aa4ae1d0af74ac9544 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Wed, 3 Apr 2019 09:52:02 +0100 Subject: [PATCH 38/50] #1264 - Changed definition of field size --- scripts/Phalcon/Mvc/Model/Migration.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/scripts/Phalcon/Mvc/Model/Migration.php b/scripts/Phalcon/Mvc/Model/Migration.php index a74179f06..a1639805c 100644 --- a/scripts/Phalcon/Mvc/Model/Migration.php +++ b/scripts/Phalcon/Mvc/Model/Migration.php @@ -311,16 +311,9 @@ public static function generate( $fieldDefinition[] = "'autoIncrement' => true"; } - if (self::$databaseConfig->path('adapter') == 'Postgresql' && - in_array($field->getType(), [Column::TYPE_BOOLEAN, Column::TYPE_INTEGER, Column::TYPE_BIGINTEGER]) - ) { - // nothing - } else { - if ($field->getSize()) { - $fieldDefinition[] = "'size' => ".$field->getSize(); - } else { - $fieldDefinition[] = "'size' => 1"; - } + if (self::columnHasSize($field->getType())) { + $columnSize = $field->getSize(); + $fieldDefinition[] = "'size' => " . ($columnSize ? $columnSize : 1); } if ($field->getScale()) { From c12c50280fc1dbeb90c0d1297230a59cc20d3478 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 20 May 2019 12:16:53 +0100 Subject: [PATCH 39/50] #1178 - Disabled lowering during usage of getters and setters --- scripts/Phalcon/Builder/Scaffold.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Phalcon/Builder/Scaffold.php b/scripts/Phalcon/Builder/Scaffold.php index cb421b7b6..95674255d 100644 --- a/scripts/Phalcon/Builder/Scaffold.php +++ b/scripts/Phalcon/Builder/Scaffold.php @@ -283,7 +283,7 @@ private function captureFilterInput($var, $fields, $useGetSetters, $identityFiel $code .= '$' . Utils::lowerCamelizeWithDelimiter($var, '-', true) . '->'; if ($useGetSetters) { - $code .= 'set' . Utils::lowerCamelizeWithDelimiter($field, '_', true) . '(' . $fieldCode . ')'; + $code .= 'set' . Utils::lowerCamelizeWithDelimiter($field, '_') . '(' . $fieldCode . ')'; } else { $code .= Utils::lowerCamelizeWithDelimiter($field, '-_', true) . ' = ' . $fieldCode; } From 288af32665745d20a34d1b95d68fed9a8778d9a6 Mon Sep 17 00:00:00 2001 From: David Gray Date: Mon, 20 May 2019 18:50:53 +0700 Subject: [PATCH 40/50] fix(AllModels): send option schema to Model --- scripts/Phalcon/Builder/AllModels.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Phalcon/Builder/AllModels.php b/scripts/Phalcon/Builder/AllModels.php index 6da194c84..2d46d806d 100644 --- a/scripts/Phalcon/Builder/AllModels.php +++ b/scripts/Phalcon/Builder/AllModels.php @@ -200,7 +200,7 @@ public function build() $modelBuilder = new Model([ 'name' => $name, 'config' => $config, - 'schema' => $schema, + 'schema' => $this->options->get('schema', ''), 'extends' => $this->options->get('extends'), 'namespace' => $this->options->get('namespace'), 'force' => $forceProcess, From 2693c647a80cc28fab1c13ca7b50e486a4a70293 Mon Sep 17 00:00:00 2001 From: David Gray Date: Mon, 20 May 2019 18:51:23 +0700 Subject: [PATCH 41/50] refactor(Model): init schema if option is not empty --- scripts/Phalcon/Builder/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Phalcon/Builder/Model.php b/scripts/Phalcon/Builder/Model.php index 749601ce5..b45a28071 100644 --- a/scripts/Phalcon/Builder/Model.php +++ b/scripts/Phalcon/Builder/Model.php @@ -159,7 +159,7 @@ public function build() $schema = Utils::resolveDbSchema($config->database); } - if ($schema) { + if (!empty($this->modelOptions->getOption('schema'))) { $initialize['schema'] = $snippet->getThisMethod('setSchema', $schema); } $initialize['source'] = $snippet->getThisMethod('setSource', $this->modelOptions->getOption('name')); From 50bb25eb653a9d9a337fa8329c0e503c7436b6c0 Mon Sep 17 00:00:00 2001 From: David Gray Date: Tue, 21 May 2019 16:27:50 +0700 Subject: [PATCH 42/50] refactor(Model): init schema if option exists and is not empty --- scripts/Phalcon/Builder/Model.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/Phalcon/Builder/Model.php b/scripts/Phalcon/Builder/Model.php index b45a28071..4e11e729d 100644 --- a/scripts/Phalcon/Builder/Model.php +++ b/scripts/Phalcon/Builder/Model.php @@ -153,15 +153,14 @@ public function build() $initialize = []; - if ($this->modelOptions->hasOption('schema')) { + // use option schema if exists and is not empty + if ($this->modelOptions->hasOption('schema') && !empty($this->modelOptions->getOption('schema'))) { $schema = $this->modelOptions->getOption('schema'); + $initialize['schema'] = $snippet->getThisMethod('setSchema', $schema); } else { $schema = Utils::resolveDbSchema($config->database); } - if (!empty($this->modelOptions->getOption('schema'))) { - $initialize['schema'] = $snippet->getThisMethod('setSchema', $schema); - } $initialize['source'] = $snippet->getThisMethod('setSource', $this->modelOptions->getOption('name')); $table = $this->modelOptions->getOption('name'); From a79523b29d162a1325c97ec0da1b86184a2ae986 Mon Sep 17 00:00:00 2001 From: David Gray Date: Tue, 21 May 2019 16:54:26 +0700 Subject: [PATCH 43/50] tests(tests/console): use --schema=devtools --- tests/console/GenerateMultyModelsCept.php | 2 +- tests/console/GenerateSingleModelCept.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/console/GenerateMultyModelsCept.php b/tests/console/GenerateMultyModelsCept.php index 4df6d5a9e..e3c193d26 100644 --- a/tests/console/GenerateMultyModelsCept.php +++ b/tests/console/GenerateMultyModelsCept.php @@ -10,7 +10,7 @@ $I->amInPath(dirname(app_path())); mkdir(tests_path('_data/console/app/models/all_model_test'), 0777, true); -$I->runShellCommand('phalcon all-models --config=app/mysql/config.php --output=app/models/all_model_test --annotate'); +$I->runShellCommand('phalcon all-models --config=app/mysql/config.php --output=app/models/all_model_test --annotate --schema=devtools'); $I->seeFileFound(app_path('models/all_model_test/TestModel.php')); $I->seeFileFound(app_path('models/all_model_test/TestModel2.php')); diff --git a/tests/console/GenerateSingleModelCept.php b/tests/console/GenerateSingleModelCept.php index c99c9f235..3cdc407ed 100644 --- a/tests/console/GenerateSingleModelCept.php +++ b/tests/console/GenerateSingleModelCept.php @@ -10,10 +10,10 @@ $I->amInPath(dirname(app_path())); mkdir(tests_path('_data/console/app/models/model_test'), 0777, true); -$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=testModel --output=app/models/model_test --annotate'); -$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=test-model2 --output=app/models/model_test --annotate'); -$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=test_model3 --output=app/models/model_test --annotate'); -$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=Testmodel4 --output=app/models/model_test --annotate'); +$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=testModel --output=app/models/model_test --annotate --schema=devtools'); +$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=test-model2 --output=app/models/model_test --annotate --schema=devtools'); +$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=test_model3 --output=app/models/model_test --annotate --schema=devtools'); +$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=Testmodel4 --output=app/models/model_test --annotate --schema=devtools'); $I->seeFileFound(app_path('models/model_test/TestModel.php')); $I->seeFileFound(app_path('models/model_test/TestModel2.php')); From 0df3a7cafcb43f85c5425f650c609711172bf608 Mon Sep 17 00:00:00 2001 From: David Gray Date: Tue, 28 May 2019 12:54:07 +0700 Subject: [PATCH 44/50] feat(AllModels): schema should default to null --- scripts/Phalcon/Builder/AllModels.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Phalcon/Builder/AllModels.php b/scripts/Phalcon/Builder/AllModels.php index 2d46d806d..9dcb8f43e 100644 --- a/scripts/Phalcon/Builder/AllModels.php +++ b/scripts/Phalcon/Builder/AllModels.php @@ -200,7 +200,7 @@ public function build() $modelBuilder = new Model([ 'name' => $name, 'config' => $config, - 'schema' => $this->options->get('schema', ''), + 'schema' => $this->options->get('schema', null), 'extends' => $this->options->get('extends'), 'namespace' => $this->options->get('namespace'), 'force' => $forceProcess, From 8a39f19edbe079dafdb0ec348daece736a69032c Mon Sep 17 00:00:00 2001 From: David Gray Date: Tue, 28 May 2019 13:59:38 +0700 Subject: [PATCH 45/50] feat(Model): add: - getModelOptions - shouldInitSchema - getSchema --- scripts/Phalcon/Builder/Model.php | 49 +++++++++- tests/unit/Builder/ModelTest.php | 150 ++++++++++++++++++++++++++++++ 2 files changed, 194 insertions(+), 5 deletions(-) create mode 100644 tests/unit/Builder/ModelTest.php diff --git a/scripts/Phalcon/Builder/Model.php b/scripts/Phalcon/Builder/Model.php index 4e11e729d..a5422474e 100644 --- a/scripts/Phalcon/Builder/Model.php +++ b/scripts/Phalcon/Builder/Model.php @@ -93,6 +93,48 @@ public function __construct(array $options) $this->modelOptions->setOption('snippet', new Snippet()); } + /** + * @return ModelOption + */ + public function getModelOptions() + { + return $this->modelOptions; + } + + /** + * We should expect schema to be string|null + * OptionsAware throws when getting null option values + * so we need to handle shouldInitSchema logic with the raw $option array + * + * Should setSchema in initialize() only if: + * - $option['schema'] !== '' + * + * @return bool + */ + public function shouldInitSchema() + { + return !isset($this->modelOptions->getOptions()['schema']) + || $this->modelOptions->getOptions()['schema'] !== ''; + } + + /** + * @return string + */ + public function getSchema() + { + if ($this->modelOptions->hasOption('schema') && !empty($this->modelOptions->getOption('schema'))) { + $schema = $this->modelOptions->getOption('schema'); + } else { + $schema = Utils::resolveDbSchema($this->modelOptions->getOption('config')->database); + } + + if (!empty($schema)) { + return $schema; + } + + throw new RuntimeException('Cannot find valid schema. Set schema argument or set in config.'); + } + /** * Module build * @@ -102,6 +144,7 @@ public function build() { $config = $this->modelOptions->getOption('config'); $snippet = $this->modelOptions->getOption('snippet'); + $schema = $this->getSchema(); if ($this->modelOptions->hasOption('directory')) { $this->path->setRootPath($this->modelOptions->getOption('directory')); @@ -153,12 +196,8 @@ public function build() $initialize = []; - // use option schema if exists and is not empty - if ($this->modelOptions->hasOption('schema') && !empty($this->modelOptions->getOption('schema'))) { - $schema = $this->modelOptions->getOption('schema'); + if ($this->shouldInitSchema()) { $initialize['schema'] = $snippet->getThisMethod('setSchema', $schema); - } else { - $schema = Utils::resolveDbSchema($config->database); } $initialize['source'] = $snippet->getThisMethod('setSource', $this->modelOptions->getOption('name')); diff --git a/tests/unit/Builder/ModelTest.php b/tests/unit/Builder/ModelTest.php new file mode 100644 index 000000000..a7f3e495c --- /dev/null +++ b/tests/unit/Builder/ModelTest.php @@ -0,0 +1,150 @@ +specify('should set default options', function() { + + $model = new Model( + [ + 'name' => 'test', + 'config' => [], + ] + ); + + $options = $model->getModelOptions()->getOptions(); + + $this->assertSame($options['camelize'], false); + $this->assertSame($options['force'], false); + $this->assertSame($options['className'], 'Test'); + $this->assertSame($options['fileName'], 'Test'); + $this->assertSame($options['abstract'], false); + $this->assertSame($options['annotate'], false); + }); + } + + public function testGetSchema() + { + $this->specify('should get schema from modelOptions if exists and not empty', function() { + $model = new Model( + [ + 'name' => 'test', + 'schema' => 'correct_schema', + 'config' => new Config([ + 'database' => [ + 'schema' => 'wrong_schema' + ] + ]), + ] + ); + $this->assertSame('correct_schema', $model->getSchema()); + }); + + $this->specify('should get schema from config->database if modelOptions schema is empty', function() { + $model = new Model( + [ + 'name' => 'test', + 'schema' => '', + 'config' => new Config([ + 'database' => [ + 'schema' => 'correct_schema' + ] + ]), + ] + ); + $this->assertSame('correct_schema', $model->getSchema()); + }); + } + + /** + * @expectedException RuntimeException + */ + public function testGetSchemaThrows() + { + $model = new Model( + [ + 'name' => 'test', + 'schema' => '', + 'config' => new Config([ + 'database' => [ + 'schema' => '' + ] + ]), + ] + ); + $model->getSchema(); + } + + public function testShouldInitSchema() + { + $this->specify('should not init if modelOption schema is ""', function (){ + $model = new Model( + [ + 'name' => 'test', + 'schema' => '', + 'config' => new Config([ + 'database' => [ + 'schema' => 'correct_schema' + ] + ]), + ] + ); + $this->assertFalse($model->shouldInitSchema()); + }); + + $this->specify('should init schema when modelOption schema is not ""', function() { + $model = new Model( + [ + 'name' => 'test', + 'schema' => 'correct_schema', + 'config' => new Config([ + 'database' => [ + 'schema' => 'correct_schema' + ] + ]), + ] + ); + + $this->assertTrue($model->shouldInitSchema()); + + $model = new Model( + [ + 'name' => 'test', + 'schema' => null, + 'config' => new Config([ + 'database' => [ + 'schema' => 'correct_schema' + ] + ]), + ] + ); + + $this->assertTrue($model->shouldInitSchema()); + + $model = new Model( + [ + 'name' => 'test', + 'config' => new Config([ + 'database' => [ + 'schema' => 'correct_schema' + ] + ]), + ] + ); + + $this->assertTrue($model->shouldInitSchema()); + }); + } +} From 6cbcbe88079ef958a09a981e5ba8b6e68c19f8f4 Mon Sep 17 00:00:00 2001 From: David Gray Date: Tue, 28 May 2019 14:01:18 +0700 Subject: [PATCH 46/50] feat(AllModels): pass raw schema to builder --- scripts/Phalcon/Builder/AllModels.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/Phalcon/Builder/AllModels.php b/scripts/Phalcon/Builder/AllModels.php index 9dcb8f43e..b30bf3426 100644 --- a/scripts/Phalcon/Builder/AllModels.php +++ b/scripts/Phalcon/Builder/AllModels.php @@ -200,7 +200,9 @@ public function build() $modelBuilder = new Model([ 'name' => $name, 'config' => $config, - 'schema' => $this->options->get('schema', null), + // We need to pass schema exactly as set in argv or config to Model + // get disallows empty values, so we need to access raw options + 'schema' => isset($this->options->schema) ? $this->options->schema : null, 'extends' => $this->options->get('extends'), 'namespace' => $this->options->get('namespace'), 'force' => $forceProcess, From e7ffb99e2d5b2f230d9b966d3634dba29940cf56 Mon Sep 17 00:00:00 2001 From: David Gray Date: Tue, 28 May 2019 14:03:50 +0700 Subject: [PATCH 47/50] test(console/Generate): add --schema="" tests --- .../console/app/models/files/TestModel5.php | 62 +++++++++++++++++++ tests/_data/schemas/mysql/dump.sql | 6 ++ tests/console/GenerateMultyModelsCept.php | 15 ++++- tests/console/GenerateSingleModelCept.php | 14 +++-- 4 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 tests/_data/console/app/models/files/TestModel5.php diff --git a/tests/_data/console/app/models/files/TestModel5.php b/tests/_data/console/app/models/files/TestModel5.php new file mode 100644 index 000000000..73c623879 --- /dev/null +++ b/tests/_data/console/app/models/files/TestModel5.php @@ -0,0 +1,62 @@ +setSource("TestModel5"); + } + + /** + * Returns table name mapped in the model. + * + * @return string + */ + public function getSource() + { + return 'TestModel5'; + } + + /** + * Allows to query a set of records that match the specified conditions + * + * @param mixed $parameters + * @return TestModel5[]|TestModel5|\Phalcon\Mvc\Model\ResultSetInterface + */ + public static function find($parameters = null) + { + return parent::find($parameters); + } + + /** + * Allows to query the first record that match the specified conditions + * + * @param mixed $parameters + * @return TestModel5|\Phalcon\Mvc\Model\ResultInterface + */ + public static function findFirst($parameters = null) + { + return parent::findFirst($parameters); + } + +} diff --git a/tests/_data/schemas/mysql/dump.sql b/tests/_data/schemas/mysql/dump.sql index bb80f6017..e42a168fa 100644 --- a/tests/_data/schemas/mysql/dump.sql +++ b/tests/_data/schemas/mysql/dump.sql @@ -91,6 +91,12 @@ CREATE TABLE `Testmodel4` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `TestModel5` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + -- -- Table structures for testing generating scaffold -- diff --git a/tests/console/GenerateMultyModelsCept.php b/tests/console/GenerateMultyModelsCept.php index e3c193d26..5c38f99ac 100644 --- a/tests/console/GenerateMultyModelsCept.php +++ b/tests/console/GenerateMultyModelsCept.php @@ -8,14 +8,16 @@ $I->wantToTest('Generating models'); $I->amInPath(dirname(app_path())); -mkdir(tests_path('_data/console/app/models/all_model_test'), 0777, true); +$dir = tests_path('_data/console/app/models/all_model_test'); +mkdir($dir, 0777, true); -$I->runShellCommand('phalcon all-models --config=app/mysql/config.php --output=app/models/all_model_test --annotate --schema=devtools'); +$I->runShellCommand('phalcon all-models --config=app/mysql/config.php --output=app/models/all_model_test --annotate'); $I->seeFileFound(app_path('models/all_model_test/TestModel.php')); $I->seeFileFound(app_path('models/all_model_test/TestModel2.php')); $I->seeFileFound(app_path('models/all_model_test/TestModel3.php')); $I->seeFileFound(app_path('models/all_model_test/Testmodel4.php')); +$I->seeFileFound(app_path('models/all_model_test/TestModel5.php')); $file1 = file_get_contents(app_path('models/files/TestModel.php')); $file2 = file_get_contents(app_path('models/files/TestModel2.php')); @@ -33,3 +35,12 @@ $I->openFile(app_path('models/all_model_test/Testmodel4.php')); $I->seeFileContentsEqual($file4); + +$I->cleanDir($dir); + +$I->runShellCommand('phalcon all-models --config=app/mysql/config.php --output=app/models/all_model_test --annotate --schema=""'); + +$file5 = file_get_contents(app_path('models/files/TestModel5.php')); + +$I->openFile(app_path('models/all_model_test/TestModel5.php')); +$I->seeFileContentsEqual($file5); diff --git a/tests/console/GenerateSingleModelCept.php b/tests/console/GenerateSingleModelCept.php index 3cdc407ed..f83519f84 100644 --- a/tests/console/GenerateSingleModelCept.php +++ b/tests/console/GenerateSingleModelCept.php @@ -10,20 +10,23 @@ $I->amInPath(dirname(app_path())); mkdir(tests_path('_data/console/app/models/model_test'), 0777, true); -$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=testModel --output=app/models/model_test --annotate --schema=devtools'); -$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=test-model2 --output=app/models/model_test --annotate --schema=devtools'); -$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=test_model3 --output=app/models/model_test --annotate --schema=devtools'); -$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=Testmodel4 --output=app/models/model_test --annotate --schema=devtools'); +$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=testModel --output=app/models/model_test --annotate'); +$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=test-model2 --output=app/models/model_test --annotate'); +$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=test_model3 --output=app/models/model_test --annotate'); +$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=Testmodel4 --output=app/models/model_test --annotate'); +$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=TestModel5 --output=app/models/model_test --annotate --schema=""'); $I->seeFileFound(app_path('models/model_test/TestModel.php')); $I->seeFileFound(app_path('models/model_test/TestModel2.php')); $I->seeFileFound(app_path('models/model_test/TestModel3.php')); $I->seeFileFound(app_path('models/model_test/Testmodel4.php')); +$I->seeFileFound(app_path('models/model_test/TestModel5.php')); $file1 = file_get_contents(app_path('models/files/TestModel.php')); $file2 = file_get_contents(app_path('models/files/TestModel2.php')); $file3 = file_get_contents(app_path('models/files/TestModel3.php')); $file4 = file_get_contents(app_path('models/files/Testmodel4.php')); +$file5 = file_get_contents(app_path('models/files/TestModel5.php')); $I->openFile(app_path('models/model_test/TestModel.php')); $I->seeFileContentsEqual($file1); @@ -36,3 +39,6 @@ $I->openFile(app_path('models/model_test/Testmodel4.php')); $I->seeFileContentsEqual($file4); + +$I->openFile(app_path('models/model_test/TestModel5.php')); +$I->seeFileContentsEqual($file5); From 7a06e89ef6ed02062d86e4e73eb024c46db63fd4 Mon Sep 17 00:00:00 2001 From: David Gray Date: Tue, 28 May 2019 14:16:33 +0700 Subject: [PATCH 48/50] test(ModelTest): add null test on testGetSchema --- tests/unit/Builder/ModelTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/unit/Builder/ModelTest.php b/tests/unit/Builder/ModelTest.php index a7f3e495c..a4fa12b01 100644 --- a/tests/unit/Builder/ModelTest.php +++ b/tests/unit/Builder/ModelTest.php @@ -66,6 +66,21 @@ public function testGetSchema() ); $this->assertSame('correct_schema', $model->getSchema()); }); + + $this->specify('should get schema from config->database if modelOptions schema is empty', function() { + $model = new Model( + [ + 'name' => 'test', + 'schema' => null, + 'config' => new Config([ + 'database' => [ + 'schema' => 'correct_schema' + ] + ]), + ] + ); + $this->assertSame('correct_schema', $model->getSchema()); + }); } /** From a81124fccbb133d2c4248ba4a3079fc5c8c3e62a Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 28 Jun 2019 15:36:05 +0100 Subject: [PATCH 49/50] #1306 - Fixed typo in namespace label --- scripts/Phalcon/Web/Tools/Views/models/generate.volt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Phalcon/Web/Tools/Views/models/generate.volt b/scripts/Phalcon/Web/Tools/Views/models/generate.volt index dd0fa953e..fd4504093 100644 --- a/scripts/Phalcon/Web/Tools/Views/models/generate.volt +++ b/scripts/Phalcon/Web/Tools/Views/models/generate.volt @@ -13,7 +13,7 @@
- +
{{ input("namespace", 'eg. My\Awesome\Namespace') }}
From aa6a2096fe2f51060a7f04c04a06f95263b461ce Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 28 Jun 2019 18:46:54 +0100 Subject: [PATCH 50/50] Revert "Fixing phalcon serve on newer PHP versions - issue #1233" --- scripts/Phalcon/Commands/Builtin/Serve.php | 4 ++-- tests/unit/ServeTest.php | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/Phalcon/Commands/Builtin/Serve.php b/scripts/Phalcon/Commands/Builtin/Serve.php index db88d8b58..cad56456d 100644 --- a/scripts/Phalcon/Commands/Builtin/Serve.php +++ b/scripts/Phalcon/Commands/Builtin/Serve.php @@ -127,12 +127,12 @@ public function shellCommand() $this->printServerDetails(); return sprintf( - '%s -S %s:%s -t %s -t %s %s', + '%s -S %s:%s -t %s %s %s', $binary_path, $this->hostname, $this->port, - $this->base_path, $this->document_root, + $this->base_path, $this->config ); } diff --git a/tests/unit/ServeTest.php b/tests/unit/ServeTest.php index 76e4f0ce8..098dc2461 100644 --- a/tests/unit/ServeTest.php +++ b/tests/unit/ServeTest.php @@ -69,7 +69,7 @@ public function testGeneratedCommandWithNoParameters() $_SERVER['argv'] = ['','']; $this->command->parseParameters([], []); $command = $this->command->shellCommand(); - $this->assertContains('php -S 0.0.0.0:8000 -t .htrouter.php -t public', $command); + $this->assertContains('php -S 0.0.0.0:8000 -t public .htrouter.php', $command); } /** @@ -103,7 +103,7 @@ public function testGeneratedCommandWithHostnameOnly() $_SERVER['argv'] = ['','', 'localhost']; $this->command->parseParameters([], []); $command = $this->command->shellCommand(); - $this->assertContains('php -S localhost:8000 -t .htrouter.php -t public', $command); + $this->assertContains('php -S localhost:8000 -t public .htrouter.php', $command); } /** @@ -137,7 +137,7 @@ public function testGeneratedCommandWithPortOnly() $_SERVER['argv'] = ['','', null, 1111]; $this->command->parseParameters([], []); $command = $this->command->shellCommand(); - $this->assertContains('php -S 0.0.0.0:1111 -t .htrouter.php -t public', $command); + $this->assertContains('php -S 0.0.0.0:1111 -t public .htrouter.php', $command); } /** @@ -171,7 +171,7 @@ public function testGeneratedCommandWithBasepathOnly() $_SERVER['argv'] = ['','', null, null, '/root/bin.php']; $this->command->parseParameters([], []); $command = $this->command->shellCommand(); - $this->assertContains('php -S 0.0.0.0:8000 -t /root/bin.php -t public', $command); + $this->assertContains('php -S 0.0.0.0:8000 -t public /root/bin.php', $command); } /** @@ -205,7 +205,7 @@ public function testGeneratedCommandWithDocumentRootOnly() $_SERVER['argv'] = ['','', null, null, null, 'not_too_public']; $this->command->parseParameters([], []); $command = $this->command->shellCommand(); - $this->assertContains('php -S 0.0.0.0:8000 -t .htrouter.php -t not_too_public', $command); + $this->assertContains('php -S 0.0.0.0:8000 -t not_too_public .htrouter.php', $command); } /** @@ -239,6 +239,6 @@ public function testGeneratedCommandWithConfigOnly() $_SERVER['argv'] = ['','', null, null, null, '--config=awesome.ini']; $this->command->parseParameters([], []); $command = $this->command->shellCommand(); - $this->assertContains('php -S 0.0.0.0:8000 -t .htrouter.php -t public -c awesome.ini', $command); + $this->assertContains('php -S 0.0.0.0:8000 -t public .htrouter.php -c awesome.ini', $command); } }