Skip to content

Commit

Permalink
Implementing -records flag to enable quick access to building fixture…
Browse files Browse the repository at this point in the history
…s off of live data. Refs #196
  • Loading branch information
markstory committed Oct 24, 2009
1 parent 857b7c2 commit 102f103
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions cake/console/libs/tasks/fixture.php
Expand Up @@ -90,6 +90,7 @@ function execute() {
}

if (isset($this->args[0])) {
$this->interactive = false;
if (!isset($this->connection)) {
$this->connection = 'default';
}
Expand All @@ -109,6 +110,7 @@ function execute() {
**/
function all() {
$this->interactive = false;
$this->Model->interactive = false;
$tables = $this->Model->listAll($this->connection, false);
foreach ($tables as $table) {
$model = $this->_modelName($table);
Expand Down Expand Up @@ -215,7 +217,7 @@ function bake($model, $useTable = false, $importOptions = array()) {
}
$records = $this->_makeRecordString($this->_generateRecords($tableInfo, $recordCount));
}
if (isset($importOptions['fromTable'])) {
if (isset($this->params['records']) || isset($importOptions['fromTable'])) {
$records = $this->_makeRecordString($this->_getRecordsFromTable($model, $useTable));
}
$out = $this->generateFixtureFile($model, compact('records', 'table', 'schema', 'import', 'fields'));
Expand Down Expand Up @@ -359,10 +361,14 @@ function _makeRecordString($records) {
* @return array Array of records.
**/
function _getRecordsFromTable($modelName, $useTable = null) {
$condition = null;
$prompt = __("Please provide a SQL fragment to use as conditions\nExample: WHERE 1=1 LIMIT 10", true);
while (!$condition) {
$condition = $this->in($prompt, null, 'WHERE 1=1 LIMIT 10');
if ($this->interactive) {
$condition = null;
$prompt = __("Please provide a SQL fragment to use as conditions\nExample: WHERE 1=1 LIMIT 10", true);
while (!$condition) {
$condition = $this->in($prompt, null, 'WHERE 1=1 LIMIT 10');
}
} else {
$condition = 'WHERE 1=1 ' . isset($this->params['count']) ? $this->params['count'] : 10;
}
App::import('Model', 'Model', false);
$modelObject =& new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
Expand Down
4 changes: 2 additions & 2 deletions cake/tests/cases/console/libs/tasks/fixture.test.php
Expand Up @@ -198,10 +198,10 @@ function testAllWithCountAndRecordsFlags() {
$this->Task->Model->setReturnValue('listAll', array('articles', 'comments'));

$filename = '/my/path/article_fixture.php';
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/title\' => \'Third Article\'/')));

$filename = '/my/path/comment_fixture.php';
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class CommentFixture/')));
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/comment\' => \'First Comment for First Article/')));
$this->Task->expectCallCount('createFile', 2);
$this->Task->all();
}
Expand Down

0 comments on commit 102f103

Please sign in to comment.