<?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; shell</title>
	<atom:link href="http://cakebaker.42dh.com/tags/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Tue, 20 Dec 2011 15:29:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</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>32</slash:comments>
		</item>
		<item>
		<title>API shell script</title>
		<link>http://cakebaker.42dh.com/2007/05/26/api-shell-script/</link>
		<comments>http://cakebaker.42dh.com/2007/05/26/api-shell-script/#comments</comments>
		<pubDate>Sat, 26 May 2007 15:54:05 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/05/26/api-shell-script/</guid>
		<description><![CDATA[Some days ago a new shell script has been added to the core of CakePHP: the API shell. It can be used to display the (public) method signatures of core classes via command line. The usage of the script is simple (even though I have to admit I understood it only after Mariano Iglesias&#8216; explanations [...]]]></description>
			<content:encoded><![CDATA[<p>Some days ago a new shell script has been added to the core of CakePHP: the API shell. It can be used to display the (public) method signatures of core classes via command line. </p>
<p>The usage of the script is simple (even though I have to admit I understood it only after <a href="http://cricava.com/blogs/mariano.php">Mariano Iglesias</a>&#8216; explanations *g*): </p>
<pre>
cake api [&lt;path&gt;] &lt;classname&gt;
</pre>
<p>&lt;path&gt; is optional, but if it is used it has to be one of the following values: &#8220;behavior&#8221;, &#8220;cache&#8221;, &#8220;controller&#8221;, &#8220;component&#8221;, &#8220;helper&#8221;, &#8220;model&#8221;, or &#8220;view&#8221;. So if you want to show the method signatures of the FormHelper, you would use this command:</p>
<pre>
cake api helper FormHelper
</pre>
<p>If no &lt;path&gt; is specified, the script looks in the cake/libs folder for the specified class.</p>
<p>Personally, I think it won&#8217;t be very useful for me, because I can request the more detailed online API documentation of a class with a simple url:</p>
<pre>

http://api.cakephp.org/1.2/class_&lt;underscored_class_name&gt;.html
</pre>
<p>Btw: On the <a href="http://www.littlehart.net/atthekeyboard/">@TheKeyboard</a> blog the grumpy guy (aka Chris Hartjes) has published a short <a href="http://www.littlehart.net/atthekeyboard/2007/05/25/screencast-interactive-console-for-cakephp/">screencast</a> to introduce another core shell script: the console. </p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/05/26/api-shell-script/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Shells and Tasks</title>
		<link>http://cakebaker.42dh.com/2007/05/16/shells-and-tasks/</link>
		<comments>http://cakebaker.42dh.com/2007/05/16/shells-and-tasks/#comments</comments>
		<pubDate>Wed, 16 May 2007 05:23:15 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[task]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/05/16/shells-and-tasks/</guid>
		<description><![CDATA[Last week I wrote about the new command line features of CakePHP 1.2. And this week it is already outdated what I wrote then ;-) The command line scripts are now called &#8220;Shells&#8221; instead of &#8220;CakeScripts&#8221;, so I adapted the previous article to those changes. With the recent changes a new concept has been introduced: [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I wrote about the new command line features of CakePHP 1.2. And this week it is already outdated what I wrote then ;-) The command line scripts are now called &#8220;Shells&#8221; instead of &#8220;CakeScripts&#8221;, so I adapted the <a href="http://cakebaker.42dh.com/2007/05/07/writing-a-custom-cakephp-console-script/">previous article</a> to those changes.</p>
<p>With the recent changes a new concept has been introduced: Tasks. Well, tasks are not entirely new as tasks were already used by bake2 (which no longer exists). But now tasks are for shells what components are for controllers. </p>
<p>Tasks are placed in app/vendors/shells/tasks if they are application-specific resp. in vendors/shells/tasks if they are general-purpose tasks. Like shell scripts, task classes have to extend the &#8220;Shell&#8221; class, but the class name has to end with &#8220;Task&#8221;. Here a simple example of a task:</p>
<pre>
// vendors/shells/tasks/test.php
class TestTask extends Shell {

    function execute() {
        // do something
    }
}
</pre>
<p>In the core tasks (and in this test task) the main function is called &#8220;execute&#8221;, but you are free to use any name you want. </p>
<p>The test task can now be used in the shell script in the following way:</p>
<pre>
// vendors/shells/demo.php
class DemoShell extends Shell {
    var $tasks = array('Test');

    function initialize() {
        // empty
    }

    function main() {
        $this-&gt;Test-&gt;execute();
    }
}
</pre>
<p>Happy baking :)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/05/16/shells-and-tasks/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>

