<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cakebaker &#187; console</title>
	<atom:link href="http://cakebaker.42dh.com/tags/console/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Mon, 19 Jul 2010 14:23:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Migrations &#8211; the CakePHP way(?)</title>
		<link>http://cakebaker.42dh.com/2008/04/13/migrations-the-cakephp-way/</link>
		<comments>http://cakebaker.42dh.com/2008/04/13/migrations-the-cakephp-way/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 15:55:19 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=594</guid>
		<description><![CDATA[A quite popular feature in Rails are migrations, a kind of version control system for database schemes. Inspired by this feature, Joel Moss started a while ago the CakePHP migrations project to bring this feature to the CakePHP world. In the meantime there is also a migrations-like feature in the Cake core, even though it [...]]]></description>
			<content:encoded><![CDATA[<p>A quite popular feature in Rails are <a href="http://wiki.rubyonrails.org/rails/pages/UnderstandingMigrations">migrations</a>, a kind of version control system for database schemes. Inspired by this feature, <a href="http://joelmoss.info">Joel Moss</a> started a while ago the <a href="http://code.google.com/p/cakephp-migrations/">CakePHP migrations project</a> to bring this feature to the CakePHP world.</p>
<p>In the meantime there is also a migrations-like feature in the Cake core, even though it seems to be a bit half-baked (or maybe I&#8217;m too stupid to understand it *g*). </p>
<p>Anyway, let&#8217;s have a look at it by using the traditional blog example.</p>
<p>First, we create a file which will contain the definitions for our schema. We name the file blog.php and place it in app/config/sql. In this file we create a class BlogSchema:</p>
<pre>
class BlogSchema extends CakeSchema {
}
</pre>
<p>Each property of a schema class represents a table, i.e. the property name is the table name, and the property value contains the table definition as an array. The definition for our posts table looks like:</p>
<pre>
class BlogSchema extends CakeSchema {
    public $posts = array(
        'id' =&gt; array('type' =&gt; 'integer', 'null' =&gt; false, 'default' =&gt; NULL, 'key' =&gt; 'primary'),
        'title' =&gt; array('type' =&gt; 'string', 'null' =&gt; false, 'length' =&gt; 100),
        'content' =&gt; array('type' =&gt; 'text', 'null' =&gt; false),
        'indexes' =&gt; array('PRIMARY' =&gt; array('column' =&gt; 'id', 'unique' =&gt; 1))
    );
}
</pre>
<p>Now, we can switch to the command line and make a test run to verify the schema script will execute the correct SQL statements:</p>
<pre>
cd cake/console
./cake schema run create blog -dry

---------------------------------------------------------------
Cake Schema Shell
---------------------------------------------------------------
Performing a dry run.

The following tables will drop.
posts

Are you sure you want to drop the tables? (y/n)
[n] &gt; y
Dropping tables.
Dry run for posts :
DROP TABLE IF EXISTS `posts`;

The following tables will create.
posts

Are you sure you want to create the tables? (y/n)
[y] &gt; y
Creating tables.
Dry run for posts :
CREATE TABLE `posts` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `title` varchar(100) NOT NULL,
        `content` text NOT NULL,
        PRIMARY KEY  (`id`)
);

End create.
</pre>
<p>Everything looks fine, so we can run the same command again, this time without the -dry parameter, and it should create the posts table.</p>
<p>Ok, now let&#8217;s add a new column &#8220;created&#8221; to our schema:</p>
<pre>
class BlogSchema extends CakeSchema {
    public $posts = array(
        'id' =&gt; array('type' =&gt; 'integer', 'null' =&gt; false, 'default' =&gt; NULL, 'key' =&gt; 'primary'),
        'title' =&gt; array('type' =&gt; 'string', 'null' =&gt; false, 'length' =&gt; 100),
        'content' =&gt; array('type' =&gt; 'text', 'null' =&gt; false),
        'created' =&gt; array('type' =&gt; 'datetime'),
        'indexes' =&gt; array('PRIMARY' =&gt; array('column' =&gt; 'id', 'unique' =&gt; 1))
    );
}
</pre>
<p>To introduce the new column we could use the command from above, which drops the table and recreates it. Or we could use the update command, which performs an &#8220;ALTER TABLE&#8221; statement to synchronize the posts table in the database with the posts table from the schema file:</p>
<pre>
./cake schema run update blog

---------------------------------------------------------------
Cake Schema Shell
---------------------------------------------------------------
Comparing Database to Schema...

The following statements will run.
ALTER TABLE `posts`
        ADD `created` datetime DEFAULT NULL;

Are you sure you want to alter the tables? (y/n)
[n] &gt; y

Updating Database...
posts updated.
End update.
</pre>
<p>With that, our blog database is up-to-date. </p>
<p>Unfortunately, the update command doesn&#8217;t work if you add a new table to the schema file, it doesn&#8217;t create this new table in the database. And so I think the migration process is currently not that useful in practice&#8230;</p>
<p>I used a question mark in the title of this article, as I am not sure if what I described here is really the correct way to use the schema feature. Please correct me, if I am wrong :)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2008/04/13/migrations-the-cakephp-way/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Faster baking with bake</title>
		<link>http://cakebaker.42dh.com/2007/12/28/faster-baking-with-bake/</link>
		<comments>http://cakebaker.42dh.com/2007/12/28/faster-baking-with-bake/#comments</comments>
		<pubDate>Fri, 28 Dec 2007 12:27:59 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[bake]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/12/28/faster-baking-with-bake/</guid>
		<description><![CDATA[Some time ago some shortcuts were added to the bake script to make it possible to skip all those questions the bake script usually asks: cake bake model User cake bake controller Users scaffold cake bake view Users For more details on those shortcuts call the bake script with the help parameter like: cake bake [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago some shortcuts were added to the bake script to make it possible to skip all those questions the bake script usually asks:</p>
<pre>
cake bake model User
cake bake controller Users scaffold
cake bake view Users
</pre>
<p>For more details on those shortcuts call the bake script with the help parameter like:</p>
<pre>
cake bake model help
</pre>
<p>or have a look at <a href="http://cakebaker.42dh.com/2007/06/06/faster-baking-of-controllers-with-the-bake-shell-script/">Faster baking of controllers with the bake shell script</a> and <a href="http://cakebaker.42dh.com/2007/06/11/baking-views/">Baking views</a>.</p>
<p>Recently, a new shortcut was added which makes the aforementioned shortcuts (almost) obsolete. With the &#8220;all&#8221; parameter it is now possible to bake with one command a model plus the corresponding controller with its views:</p>
<pre>
cake bake all  // asks you for the model name
cake bake all User
</pre>
<p>This feature is currently only available in the development branch, but the next release is probably not that far away&#8230;</p>
<p>Happy baking :)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/12/28/faster-baking-with-bake/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Bash completion script for CakePHP&#8217;s console</title>
		<link>http://cakebaker.42dh.com/2007/07/20/bash-completion-script-for-cakephps-console/</link>
		<comments>http://cakebaker.42dh.com/2007/07/20/bash-completion-script-for-cakephps-console/#comments</comments>
		<pubDate>Fri, 20 Jul 2007 13:04:56 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[bake]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[console]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/07/20/bash-completion-script-for-cakephps-console/</guid>
		<description><![CDATA[Travis Cline (aka tclineks) posted in a comment to the article &#8220;Faster baking of controllers with the bake shell script&#8221; a link to a bash completion script he started to write for CakePHP&#8217;s console. As I didn&#8217;t understood what his script did nor how to use it, Travis explained it in the following way: It [...]]]></description>
			<content:encoded><![CDATA[<p>Travis Cline (aka tclineks) posted in a comment to the article <a href="http://cakebaker.42dh.com/2007/06/06/faster-baking-of-controllers-with-the-bake-shell-script">&#8220;Faster baking of controllers with the bake shell script&#8221;</a> a link to a <a href="http://bin.cakephp.org/saved/21917">bash completion script</a> he started to write for CakePHP&#8217;s console. </p>
<p>As I didn&#8217;t understood what his script did nor how to use it, Travis explained it in the following way:</p>
<blockquote><p>
It [the bash completion script] gives you bash completion (through hitting tab) for shells and for the bake it gives you bake actions and will autocomplete potential model/view/controller names.<br />
<br />
Here&#8217;s an intro to bash_completion: <a href="http://www.debian-administration.org/articles/316">http://www.debian-administration.org/articles/316</a><br />
<br />
So,<br />
after I source this (`. bashcompletion`, `source bashcompletion`, or link it in the right location -&gt; /etc/bash_completion.d/) I can type</p>
<pre>
`(path to console)/cake [tab][tab]`
</pre>
<p>and it lists the potential shells to use e.g. acl, api, bake (even app-specific shells)</p>
<pre>
`/cake b[tab]` -&gt; completes 'bake'

`/cake bake m[tab]` -&gt; completes 'model'
</pre>
<p>If I further do </p>
<pre>
`/cake bake model M[tab][tab]` it'll complete for models beginning with 'M'
</pre>
<p>It&#8217;s pretty crude atm &#8212; doesn&#8217;t handle -app params (you can invoke the console within the custom app dir for now).</p>
<p>If bake.php/shell is enhanced to support public, noninteractive listing this could be pretty sweet.
</p></blockquote>
<p>The bash completion provided by this script when using the CakePHP console is really handy. Thanks Travis!</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/07/20/bash-completion-script-for-cakephps-console/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Writing a custom CakePHP console script</title>
		<link>http://cakebaker.42dh.com/2007/05/07/writing-a-custom-cakephp-console-script/</link>
		<comments>http://cakebaker.42dh.com/2007/05/07/writing-a-custom-cakephp-console-script/#comments</comments>
		<pubDate>Mon, 07 May 2007 16:01:35 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[console]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/05/07/writing-a-custom-cakephp-console-script/</guid>
		<description><![CDATA[As you may have noticed, last weekend all command line related files in CakePHP 1.2 have been moved from /cake/scripts to /cake/console. Coupled with this move was a change in the way you use the command line scripts. Instead of php bake.php -app /path_to_app_dir you now have to use ./cake bake -app /path_to_app_dir to run [...]]]></description>
			<content:encoded><![CDATA[<p>As you may have noticed, last weekend all command line related files in CakePHP 1.2 have been moved from /cake/scripts to /cake/console. Coupled with this move was a change in the way you use the command line scripts. Instead of</p>
<pre>
php bake.php -app /path_to_app_dir
</pre>
<p>you now have to use </p>
<pre>
./cake bake -app /path_to_app_dir
</pre>
<p>to run the bake script. The ACL script can be used in a similar way. </p>
<p>This switch to the new console is probably the end of bake2, as it doesn&#8217;t (yet) work with the console, and the console provides a similar functionality as bake2, i.e. the console allows you to execute your own command line scripts. In the meantime the bake2 script has been removed from the repository. (Update 2007-05-15: The bake2 script has been removed from the repository)</p>
<p>Writing such a command line script (or shell scripts as they are called in CakePHP) is easy, so let us write a simple script which creates a file specified by the user. The custom scripts are placed in /app/vendors/shells, if they are specific to an application, or in /vendors/shells, if they are generic.</p>
<p>In our case it doesn&#8217;t matter where we place the file as it is only an example, so we put it to /vendors/shells. A shell class has to extend the class &#8220;Shell&#8221; and the class name has to end with &#8220;Shell&#8221;. All public functions of a shell class are treated as &#8220;commands&#8221;, i.e. they can be called directly via command line. What the &#8220;index&#8221; function is for controllers, is the &#8220;main&#8221; function for shell scripts. It is automatically called if you don&#8217;t specify a different command.</p>
<p>In our case we also have to override the &#8220;initialize&#8221; function, as we don&#8217;t have a database.php file in app/config (else we would get an error). The code for our shell script is straight-forward and should be self-explanatory:</p>
<pre>
// vendors/shells/demo.php
class DemoShell extends Shell {

    function initialize() {
        // empty
    }

    function main() {
        $this-&gt;out('Demo Script');
        $this-&gt;hr();

        if (count($this-&gt;args) === 0) {
            $filename = $this-&gt;in('Please enter the filename:');
        } else {
            $filename = $this-&gt;args[0];
        }
        $this-&gt;createFile(TMP.$filename, 'Test content');
    }

    function help() {
        $this-&gt;out('Here comes the help message');
    }
}
</pre>
<p>This script can now be executed in one of the following ways:</p>
<pre>
./cake demo  // asks the user for a file name
./cake demo test.txt   // uses the specified file name
./cake demo help   // shows the help message
</pre>
<p>Happy baking :)</p>
<p>Update (2007-05-13): Adapted to the latest changes in the code (CakeScript has been renamed to Shell)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/05/07/writing-a-custom-cakephp-console-script/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
	</channel>
</rss>
