2009-04-29 00:32:15 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-07-17 03:55:41 +00:00
|
|
|
* The FixtureTask handles creating and updating fixture files.
|
2009-04-29 00:32:15 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
|
2009-07-17 03:55:41 +00:00
|
|
|
* Copyright 2005-2009, Cake Software Foundation, Inc.
|
2009-04-29 00:32:15 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.console.libs.tasks
|
|
|
|
* @since CakePHP(tm) v 1.3
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
|
|
*/
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-29 00:32:15 +00:00
|
|
|
/**
|
|
|
|
* Task class for creating and updating fixtures files.
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.console.libs.tasks
|
|
|
|
*/
|
|
|
|
class FixtureTask extends Shell {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-29 00:32:15 +00:00
|
|
|
/**
|
|
|
|
* Name of plugin
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $plugin = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-29 00:32:15 +00:00
|
|
|
/**
|
|
|
|
* Tasks to be loaded by this Task
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2009-05-13 01:26:37 +00:00
|
|
|
var $tasks = array('DbConfig', 'Model', 'Template');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-29 00:32:15 +00:00
|
|
|
/**
|
|
|
|
* path to fixtures directory
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $path = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-04 01:43:22 +00:00
|
|
|
/**
|
|
|
|
* The db connection being used for baking
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
**/
|
|
|
|
var $connection = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-20 04:59:18 +00:00
|
|
|
/**
|
|
|
|
* Schema instance
|
|
|
|
*
|
|
|
|
* @var object
|
|
|
|
**/
|
|
|
|
var $_Schema = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-29 00:32:15 +00:00
|
|
|
/**
|
|
|
|
* Override initialize
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2009-06-07 00:03:04 +00:00
|
|
|
function __construct(&$dispatch) {
|
|
|
|
parent::__construct($dispatch);
|
2009-04-29 00:32:15 +00:00
|
|
|
$this->path = $this->params['working'] . DS . 'tests' . DS . 'fixtures' . DS;
|
2009-04-30 00:52:12 +00:00
|
|
|
if (!class_exists('CakeSchema')) {
|
2009-07-30 22:01:22 +00:00
|
|
|
App::import('Model', 'CakeSchema', false);
|
2009-04-30 00:52:12 +00:00
|
|
|
}
|
2009-04-29 00:32:15 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-29 00:32:15 +00:00
|
|
|
/**
|
|
|
|
* Execution method always used for tasks
|
2009-05-04 01:43:22 +00:00
|
|
|
* Handles dispatching to interactive, named, or all processess.
|
2009-04-29 00:32:15 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function execute() {
|
|
|
|
if (empty($this->args)) {
|
|
|
|
$this->__interactive();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($this->args[0])) {
|
2009-05-08 03:59:43 +00:00
|
|
|
if (!isset($this->connection)) {
|
|
|
|
$this->connection = 'default';
|
|
|
|
}
|
2009-04-29 00:32:15 +00:00
|
|
|
if (strtolower($this->args[0]) == 'all') {
|
|
|
|
return $this->all();
|
|
|
|
}
|
2009-04-30 00:52:12 +00:00
|
|
|
$model = Inflector::camelize($this->args[0]);
|
2009-05-08 03:59:43 +00:00
|
|
|
$this->bake($model);
|
2009-04-29 00:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-29 00:32:15 +00:00
|
|
|
/**
|
|
|
|
* Bake All the Fixtures at once. Will only bake fixtures for models that exist.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function all() {
|
2009-04-30 02:50:43 +00:00
|
|
|
$this->interactive = false;
|
2009-05-04 01:43:22 +00:00
|
|
|
$tables = $this->Model->listAll($this->connection, false);
|
2009-04-30 02:50:43 +00:00
|
|
|
foreach ($tables as $table) {
|
|
|
|
$model = $this->_modelName($table);
|
|
|
|
$this->bake($model);
|
|
|
|
}
|
2009-04-29 00:32:15 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-29 00:32:15 +00:00
|
|
|
/**
|
|
|
|
* Interactive baking function
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
2009-05-05 03:08:15 +00:00
|
|
|
function __interactive() {
|
2009-04-29 00:45:07 +00:00
|
|
|
$this->interactive = true;
|
|
|
|
$this->hr();
|
|
|
|
$this->out(sprintf("Bake Fixture\nPath: %s", $this->path));
|
|
|
|
$this->hr();
|
|
|
|
|
2009-05-04 01:43:22 +00:00
|
|
|
$useDbConfig = $this->connection;
|
|
|
|
if (!isset($this->connection)) {
|
|
|
|
$this->connection = $this->DbConfig->getConfig();
|
|
|
|
}
|
|
|
|
$modelName = $this->Model->getName($this->connection);
|
|
|
|
$useTable = $this->Model->getTable($modelName, $this->connection);
|
2009-04-30 00:52:12 +00:00
|
|
|
$importOptions = $this->importOptions($modelName);
|
|
|
|
$this->bake($modelName, $useTable, $importOptions);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-30 00:52:12 +00:00
|
|
|
/**
|
|
|
|
* Interacts with the User to setup an array of import options. For a fixture.
|
|
|
|
*
|
|
|
|
* @param string $modelName Name of model you are dealing with.
|
|
|
|
* @return array Array of import options.
|
|
|
|
**/
|
|
|
|
function importOptions($modelName) {
|
|
|
|
$options = array();
|
2009-07-20 04:59:18 +00:00
|
|
|
$doSchema = $this->in(__('Would you like to import schema for this fixture?', true), array('y', 'n'), 'n');
|
2009-04-30 00:52:12 +00:00
|
|
|
if ($doSchema == 'y') {
|
|
|
|
$options['schema'] = $modelName;
|
|
|
|
}
|
2009-07-20 04:59:18 +00:00
|
|
|
$doRecords = $this->in(__('Would you like to use record importing for this fixture?', true), array('y', 'n'), 'n');
|
2009-04-30 00:52:12 +00:00
|
|
|
if ($doRecords == 'y') {
|
|
|
|
$options['records'] = true;
|
|
|
|
}
|
2009-07-20 04:59:18 +00:00
|
|
|
if ($doRecords == 'n') {
|
|
|
|
$prompt = sprintf(__("Would you like to build this fixture with data from %s's table?", true), $modelName);
|
2009-07-21 04:00:39 +00:00
|
|
|
$fromTable = $this->in($prompt, array('y', 'n'), 'n');
|
|
|
|
if (strtolower($fromTable) == 'y') {
|
2009-07-20 04:59:18 +00:00
|
|
|
$options['fromTable'] = true;
|
|
|
|
}
|
|
|
|
}
|
2009-04-30 00:52:12 +00:00
|
|
|
return $options;
|
2009-04-29 00:32:15 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-29 00:32:15 +00:00
|
|
|
/**
|
|
|
|
* Assembles and writes a Fixture file
|
|
|
|
*
|
2009-04-30 00:52:12 +00:00
|
|
|
* @param string $model Name of model to bake.
|
|
|
|
* @param string $useTable Name of table to use.
|
|
|
|
* @param array $importOptions Options for var $import
|
2009-04-29 00:32:15 +00:00
|
|
|
* @return string Baked fixture
|
|
|
|
* @access private
|
|
|
|
*/
|
2009-04-30 00:52:12 +00:00
|
|
|
function bake($model, $useTable = false, $importOptions = array()) {
|
2009-07-21 04:00:39 +00:00
|
|
|
$table = $schema = $records = $import = $modelImport = $recordImport = null;
|
2009-04-30 00:52:12 +00:00
|
|
|
if (!$useTable) {
|
|
|
|
$useTable = Inflector::tableize($model);
|
|
|
|
} elseif ($useTable != Inflector::tableize($model)) {
|
2009-05-11 02:16:38 +00:00
|
|
|
$table = $useTable;
|
2009-04-30 00:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($importOptions)) {
|
|
|
|
if (isset($importOptions['schema'])) {
|
|
|
|
$modelImport = "'model' => '{$importOptions['schema']}'";
|
|
|
|
}
|
|
|
|
if (isset($importOptions['records'])) {
|
2009-05-04 01:43:22 +00:00
|
|
|
$recordImport = "'records' => true";
|
|
|
|
}
|
|
|
|
if ($modelImport && $recordImport) {
|
|
|
|
$modelImport .= ', ';
|
2009-04-30 00:52:12 +00:00
|
|
|
}
|
2009-07-21 04:00:39 +00:00
|
|
|
if (!empty($modelImport) || !empty($recordImport)) {
|
|
|
|
$import = sprintf("array(%s%s)", $modelImport, $recordImport);
|
|
|
|
}
|
2009-04-30 00:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->_Schema = new CakeSchema();
|
2009-05-04 01:43:22 +00:00
|
|
|
$data = $this->_Schema->read(array('models' => false, 'connection' => $this->connection));
|
2009-04-30 00:52:12 +00:00
|
|
|
|
|
|
|
if (!isset($data['tables'][$useTable])) {
|
|
|
|
$this->err('Could not find your selected table ' . $useTable);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tableInfo = $data['tables'][$useTable];
|
|
|
|
if (is_null($modelImport)) {
|
2009-05-11 02:16:38 +00:00
|
|
|
$schema = $this->_generateSchema($tableInfo);
|
2009-04-30 00:52:12 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 04:00:39 +00:00
|
|
|
if (!isset($importOptions['records']) && !isset($importOptions['fromTable'])) {
|
2009-04-30 00:52:12 +00:00
|
|
|
$recordCount = 1;
|
|
|
|
if (isset($this->params['count'])) {
|
|
|
|
$recordCount = $this->params['count'];
|
|
|
|
}
|
2009-07-21 04:00:39 +00:00
|
|
|
$records = $this->_makeRecordString($this->_generateRecords($tableInfo, $recordCount));
|
|
|
|
}
|
|
|
|
if (isset($importOptions['fromTable'])) {
|
|
|
|
$records = $this->_makeRecordString($this->_getRecordsFromTable($model, $useTable));
|
2009-04-30 00:52:12 +00:00
|
|
|
}
|
2009-05-11 02:16:38 +00:00
|
|
|
$out = $this->generateFixtureFile($model, compact('records', 'table', 'schema', 'import', 'fields'));
|
2009-05-04 01:43:22 +00:00
|
|
|
return $out;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-04 01:43:22 +00:00
|
|
|
/**
|
|
|
|
* Generate the fixture file, and write to disk
|
|
|
|
*
|
|
|
|
* @param string $model name of the model being generated
|
|
|
|
* @param string $fixture Contents of the fixture file.
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
**/
|
2009-05-11 02:16:38 +00:00
|
|
|
function generateFixtureFile($model, $otherVars) {
|
|
|
|
$defaults = array('table' => null, 'schema' => null, 'records' => null, 'import' => null, 'fields' => null);
|
|
|
|
$vars = array_merge($defaults, $otherVars);
|
2009-06-07 00:03:04 +00:00
|
|
|
|
2009-05-04 01:43:22 +00:00
|
|
|
$path = $this->path;
|
2009-04-30 00:52:12 +00:00
|
|
|
if (isset($this->plugin)) {
|
2009-06-07 00:03:04 +00:00
|
|
|
$path = $this->_pluginPath($this->plugin) . 'tests' . DS . 'fixtures' . DS;
|
2009-04-30 00:52:12 +00:00
|
|
|
}
|
2009-05-04 01:43:22 +00:00
|
|
|
$filename = Inflector::underscore($model) . '_fixture.php';
|
2009-05-11 02:16:38 +00:00
|
|
|
|
2009-05-13 01:26:37 +00:00
|
|
|
$this->Template->set('model', $model);
|
|
|
|
$this->Template->set($vars);
|
2009-07-01 04:50:38 +00:00
|
|
|
$content = $this->Template->generate('classes', 'fixture');
|
2009-05-11 02:16:38 +00:00
|
|
|
|
2009-04-30 00:52:12 +00:00
|
|
|
$this->out("\nBaking test fixture for $model...");
|
|
|
|
$this->createFile($path . $filename, $content);
|
2009-05-11 02:16:38 +00:00
|
|
|
return $content;
|
2009-04-30 00:52:12 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-30 00:52:12 +00:00
|
|
|
/**
|
|
|
|
* Generates a string representation of a schema.
|
|
|
|
*
|
|
|
|
* @param array $table Table schema array
|
|
|
|
* @return string fields definitions
|
|
|
|
**/
|
|
|
|
function _generateSchema($tableInfo) {
|
|
|
|
$cols = array();
|
2009-05-11 02:16:38 +00:00
|
|
|
$out = "array(\n";
|
2009-04-30 00:52:12 +00:00
|
|
|
foreach ($tableInfo as $field => $fieldInfo) {
|
|
|
|
if (is_array($fieldInfo)) {
|
2009-09-29 15:30:02 +00:00
|
|
|
if (!in_array($field, array('indexes', 'tableParameters'))) {
|
2009-04-30 00:52:12 +00:00
|
|
|
$col = "\t\t'{$field}' => array('type'=>'" . $fieldInfo['type'] . "', ";
|
|
|
|
$col .= join(', ', $this->_Schema->__values($fieldInfo));
|
2009-09-29 15:30:02 +00:00
|
|
|
} elseif ($field == 'indexes') {
|
2009-04-30 00:52:12 +00:00
|
|
|
$col = "\t\t'indexes' => array(";
|
|
|
|
$props = array();
|
|
|
|
foreach ((array)$fieldInfo as $key => $index) {
|
|
|
|
$props[] = "'{$key}' => array(".join(', ', $this->_Schema->__values($index)).")";
|
|
|
|
}
|
|
|
|
$col .= join(', ', $props);
|
2009-09-29 15:30:02 +00:00
|
|
|
} elseif ($field == 'tableParameters') {
|
|
|
|
//@todo add charset, collate and engine here
|
|
|
|
$col = "\t\t'tableParameters' => array(";
|
|
|
|
$props = array();
|
|
|
|
foreach ((array)$fieldInfo as $key => $param) {
|
|
|
|
$props[] = "'{$key}' => '$param'";
|
|
|
|
}
|
|
|
|
$col .= join(', ', $props);
|
2009-04-30 00:52:12 +00:00
|
|
|
}
|
|
|
|
$col .= ")";
|
|
|
|
$cols[] = $col;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$out .= join(",\n", $cols);
|
2009-05-11 02:16:38 +00:00
|
|
|
$out .= "\n\t)";
|
2009-04-30 00:52:12 +00:00
|
|
|
return $out;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-30 00:52:12 +00:00
|
|
|
/**
|
|
|
|
* Generate String representation of Records
|
|
|
|
*
|
|
|
|
* @param array $table Table schema array
|
2009-07-21 04:00:39 +00:00
|
|
|
* @return array Array of records to use in the fixture.
|
2009-04-30 00:52:12 +00:00
|
|
|
**/
|
|
|
|
function _generateRecords($tableInfo, $recordCount = 1) {
|
2009-07-21 04:00:39 +00:00
|
|
|
$records = array();
|
2009-04-30 00:52:12 +00:00
|
|
|
for ($i = 0; $i < $recordCount; $i++) {
|
2009-07-21 04:00:39 +00:00
|
|
|
$record = array();
|
2009-04-30 00:52:12 +00:00
|
|
|
foreach ($tableInfo as $field => $fieldInfo) {
|
|
|
|
if (empty($fieldInfo['type'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch ($fieldInfo['type']) {
|
|
|
|
case 'integer':
|
|
|
|
$insert = $i + 1;
|
|
|
|
break;
|
|
|
|
case 'string';
|
2009-07-21 04:00:39 +00:00
|
|
|
$isPrimaryUuid = (
|
|
|
|
isset($fieldInfo['key']) && strtolower($fieldInfo['key']) == 'primary' &&
|
|
|
|
isset($fieldInfo['length']) && $fieldInfo['length'] == 36
|
|
|
|
);
|
|
|
|
if ($isPrimaryUuid) {
|
|
|
|
$insert = String::uuid();
|
|
|
|
} else {
|
|
|
|
$insert = "Lorem ipsum dolor sit amet";
|
|
|
|
if (!empty($fieldInfo['length'])) {
|
|
|
|
$insert = substr($insert, 0, (int)$fieldInfo['length'] - 2);
|
|
|
|
}
|
2009-04-30 00:52:12 +00:00
|
|
|
}
|
|
|
|
$insert = "'$insert'";
|
|
|
|
break;
|
2009-04-30 02:50:43 +00:00
|
|
|
case 'timestamp':
|
|
|
|
$ts = time();
|
|
|
|
$insert = "'$ts'";
|
|
|
|
break;
|
2009-04-30 00:52:12 +00:00
|
|
|
case 'datetime':
|
|
|
|
$ts = date('Y-m-d H:i:s');
|
|
|
|
$insert = "'$ts'";
|
|
|
|
break;
|
|
|
|
case 'date':
|
|
|
|
$ts = date('Y-m-d');
|
|
|
|
$insert = "'$ts'";
|
|
|
|
break;
|
|
|
|
case 'time':
|
|
|
|
$ts = date('H:i:s');
|
|
|
|
$insert = "'$ts'";
|
|
|
|
break;
|
|
|
|
case 'boolean':
|
|
|
|
$insert = 1;
|
|
|
|
break;
|
|
|
|
case 'text':
|
|
|
|
$insert = "'Lorem ipsum dolor sit amet, aliquet feugiat.";
|
|
|
|
$insert .= " Convallis morbi fringilla gravida,";
|
|
|
|
$insert .= " phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin";
|
|
|
|
$insert .= " venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla";
|
|
|
|
$insert .= " vestibulum massa neque ut et, id hendrerit sit,";
|
|
|
|
$insert .= " feugiat in taciti enim proin nibh, tempor dignissim, rhoncus";
|
|
|
|
$insert .= " duis vestibulum nunc mattis convallis.'";
|
|
|
|
break;
|
|
|
|
}
|
2009-07-21 04:00:39 +00:00
|
|
|
$record[$field] = $insert;
|
|
|
|
}
|
|
|
|
$records[] = $record;
|
|
|
|
}
|
|
|
|
return $records;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-21 04:00:39 +00:00
|
|
|
/**
|
|
|
|
* Convert a $records array into a a string.
|
|
|
|
*
|
|
|
|
* @param array $records Array of records to be converted to string
|
|
|
|
* @return string A string value of the $records array.
|
|
|
|
**/
|
|
|
|
function _makeRecordString($records) {
|
|
|
|
$out = "array(\n";
|
|
|
|
foreach ($records as $record) {
|
|
|
|
$values = array();
|
|
|
|
foreach ($record as $field => $value) {
|
|
|
|
$values[] = "\t\t\t'$field' => $value";
|
2009-04-30 00:52:12 +00:00
|
|
|
}
|
|
|
|
$out .= "\t\tarray(\n";
|
2009-07-21 04:00:39 +00:00
|
|
|
$out .= implode(",\n", $values);
|
2009-04-30 00:52:12 +00:00
|
|
|
$out .= "\n\t\t),\n";
|
|
|
|
}
|
2009-05-11 02:16:38 +00:00
|
|
|
$out .= "\t)";
|
2009-04-30 00:52:12 +00:00
|
|
|
return $out;
|
2009-04-29 00:32:15 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-21 04:00:39 +00:00
|
|
|
/**
|
|
|
|
* Interact with the user to get a custom SQL condition and use that to extract data
|
|
|
|
* to build a fixture.
|
2009-07-24 19:18:37 +00:00
|
|
|
*
|
2009-07-21 04:00:39 +00:00
|
|
|
* @param string $modelName name of the model to take records from.
|
|
|
|
* @param string $useTable Name of table to use.
|
|
|
|
* @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');
|
|
|
|
}
|
2009-07-30 22:01:22 +00:00
|
|
|
App::import('Model', 'Model', false);
|
2009-07-21 04:00:39 +00:00
|
|
|
$modelObject =& new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
|
|
|
|
$records = $modelObject->find('all', array(
|
|
|
|
'conditions' => $condition,
|
|
|
|
'recursive' => -1
|
|
|
|
));
|
2009-08-02 22:17:31 +00:00
|
|
|
$db =& ConnectionManager::getDataSource($modelObject->useDbConfig);
|
2009-07-21 04:00:39 +00:00
|
|
|
$schema = $modelObject->schema();
|
|
|
|
$out = array();
|
|
|
|
foreach ($records as $record) {
|
|
|
|
$row = array();
|
|
|
|
foreach ($record[$modelObject->alias] as $field => $value) {
|
|
|
|
$row[$field] = $db->value($value, $schema[$field]['type']);
|
|
|
|
}
|
|
|
|
$out[] = $row;
|
|
|
|
}
|
|
|
|
return $out;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-29 00:32:15 +00:00
|
|
|
/**
|
|
|
|
* Displays help contents
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function help() {
|
|
|
|
$this->hr();
|
2009-04-30 02:40:49 +00:00
|
|
|
$this->out("Usage: cake bake fixture <arg1> <params>");
|
2009-04-29 00:32:15 +00:00
|
|
|
$this->hr();
|
|
|
|
$this->out('Commands:');
|
2009-04-30 02:40:49 +00:00
|
|
|
$this->out("\nfixture <name>\n\tbakes fixture with specified name.");
|
|
|
|
$this->out("\nfixture all\n\tbakes all fixtures.");
|
2009-09-26 21:08:37 +00:00
|
|
|
$this->out();
|
2009-05-04 01:43:22 +00:00
|
|
|
$this->out('Parameters:');
|
2009-07-21 04:00:39 +00:00
|
|
|
$this->out("\t-count When using generated data, the number of records to include in the fixture(s).");
|
2009-05-30 04:46:25 +00:00
|
|
|
$this->out("\t-connection Which database configuration to use for baking.");
|
2009-08-17 01:32:10 +00:00
|
|
|
$this->out("\t-plugin CamelCased name of plugin to bake fixtures for.");
|
2009-09-27 20:28:26 +00:00
|
|
|
$this->out();
|
2009-04-29 00:32:15 +00:00
|
|
|
$this->_stop();
|
|
|
|
}
|
|
|
|
}
|
2009-07-17 03:55:41 +00:00
|
|
|
?>
|