-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
2,026 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="./tests/bootstrap.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
stopOnIncomplete="false" | ||
stopOnSkipped="false" | ||
syntaxCheck="false"> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
bootstrap="./tests/bootstrap.php" | ||
> | ||
|
||
<testsuites> | ||
<testsuite name="Migrations"> | ||
<directory>./tests/</directory> | ||
<testsuite name="Migrations Test Suite"> | ||
<directory>./tests/TestCase</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<!-- Setup a listener for fixtures --> | ||
<listeners> | ||
<listener | ||
class="\Cake\TestSuite\Fixture\FixtureInjector" | ||
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php"> | ||
<arguments> | ||
<object class="\Cake\TestSuite\Fixture\FixtureManager" /> | ||
</arguments> | ||
</listener> | ||
</listeners> | ||
|
||
<!-- Prevent coverage reports from looking in tests and vendors --> | ||
<filter> | ||
<blacklist> | ||
<directory suffix=".php">./vendor/</directory> | ||
<directory suffix=".ctp">./vendor/</directory> | ||
|
||
<directory suffix=".php">./tests/</directory> | ||
<directory suffix=".ctp">./tests/</directory> | ||
</blacklist> | ||
</filter> | ||
|
||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?php | ||
/** | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org CakePHP(tm) Project | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Migrations\Shell\Task; | ||
|
||
use Cake\Core\Configure; | ||
use Cake\Core\Plugin; | ||
use Cake\Filesystem\File; | ||
use Migrations\Shell\Task\SimpleMigrationTask; | ||
|
||
/** | ||
* Task class for generating migration snapshot files. | ||
*/ | ||
class MigrationSnapshotTask extends SimpleMigrationTask | ||
{ | ||
/** | ||
* Tables to skip | ||
* | ||
* @var array | ||
*/ | ||
public $skipTables = ['i18n', 'phinxlog']; | ||
|
||
/** | ||
* Regex of Table name to skip | ||
* | ||
* @var string | ||
*/ | ||
public $skipTablesRegex = '_phinxlog'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function template() | ||
{ | ||
return 'Migrations.config/snapshot'; | ||
} | ||
|
||
public function templateData() | ||
{ | ||
$ns = Configure::read('App.namespace'); | ||
$pluginPath = ''; | ||
if ($this->plugin) { | ||
$ns = $this->plugin; | ||
$pluginPath = $this->plugin . '.'; | ||
} | ||
|
||
$collection = $this->getCollection($this->connection); | ||
|
||
$tables = $collection->listTables(); | ||
foreach ($tables as $num => $table) { | ||
if ((in_array($table, $this->skipTables)) || (strpos($table, $this->skipTablesRegex) !== false)) { | ||
unset($tables[$num]); | ||
continue; | ||
} | ||
|
||
if (!$this->tableToAdd($table, $this->plugin)) { | ||
unset($tables[$num]); | ||
continue; | ||
} | ||
} | ||
|
||
return [ | ||
'plugin' => $this->plugin, | ||
'pluginPath' => $pluginPath, | ||
'namespace' => $ns, | ||
'collection' => $collection, | ||
'tables' => $tables, | ||
'action' => 'create_table', | ||
'name' => $this->Template->viewVars['name'], | ||
]; | ||
} | ||
|
||
/** | ||
* To check if a Table Model is to be added in the migration file | ||
* | ||
* @param string $tableName Table name in underscore case | ||
* @param string $pluginName Plugin name if exists | ||
* @return bool true if the model is to be added | ||
*/ | ||
public function tableToAdd($tableName, $pluginName = null) | ||
{ | ||
if ($this->params['require-table'] === true) { | ||
return $this->tableExists(Inflector::camelize($tableName), $pluginName); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* To check if a Table Model exists in the path of model | ||
* | ||
* @param string $tableName Table name in underscore case | ||
* @param string $pluginName Plugin name if exists | ||
* @return bool | ||
*/ | ||
public function tableExists($tableName, $pluginName = null) | ||
{ | ||
$file = new File($this->getModelPath($pluginName) . $tableName . 'Table.php'); | ||
return $file->exists(); | ||
} | ||
|
||
/** | ||
* Path for Table folder | ||
* | ||
* @param string $pluginName Plugin name if exists | ||
* @return string : path to Table Folder. Default to App Table Path | ||
*/ | ||
public function getModelPath($pluginName = null) | ||
{ | ||
if (!is_null($pluginName) && Plugin::loaded($pluginName)) { | ||
return Plugin::classPath($pluginName) . 'Model' . DS . 'Table' . DS; | ||
} | ||
return APP . 'Model' . DS . 'Table' . DS; | ||
} | ||
|
||
/** | ||
* Gets the option parser instance and configures it. | ||
* | ||
* @return \Cake\Console\ConsoleOptionParser | ||
*/ | ||
public function getOptionParser() | ||
{ | ||
$parser = parent::getOptionParser(); | ||
|
||
$parser->description( | ||
'Bake migration snapshot class.' | ||
)->addOption('require-table', [ | ||
'boolean' => true, | ||
'default' => false, | ||
'help' => 'If require-table is set to true, check also that the table class exists.' | ||
]); | ||
|
||
return $parser; | ||
} | ||
} |
Oops, something went wrong.