Index: plugins/apostrophePlugin/trunk/lib/task/rebuildslugsTask.class.php
===================================================================
--- plugins/apostrophePlugin/trunk/lib/task/rebuildslugsTask.class.php	(revision 0)
+++ plugins/apostrophePlugin/trunk/lib/task/rebuildslugsTask.class.php	(revision 0)
@@ -0,0 +1,96 @@
+<?php
+/*
+
+Copyright (c) 2010 Euranova
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+/**
+ * rebuildslugsTask
+ * 
+ * Generate slugs from apostrophe tree. 
+ * 
+ * @author Jehan Bruggeman <jehanbruggeman at gmail dot com>
+ *
+ */
+
+class rebuildslugsTask extends sfBaseTask
+{
+  protected function configure()
+  {
+
+    $this->addOptions(array(
+      new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name'),
+      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
+      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
+    ));
+
+    $this->namespace        = 'apostrophe';
+    $this->name             = 'rebuild-slugs';
+    $this->briefDescription = 'Rebuild the slugs to reflect the current tree';
+    $this->detailedDescription = <<<EOF
+The [apostrohe:rebuild-slugs|INFO] task updates the slugs of your pages  to reflect the Doctrine
+nested set tree of your site.
+
+Call it with:
+
+  [php symfony a:rebuild-slugs|INFO]
+EOF;
+  }
+
+  protected function execute($arguments = array(), $options = array())
+  {
+  	// retreive pages
+    $databaseManager = new sfDatabaseManager($this->configuration);
+    $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
+    $root = aPageTable::retrieveBySlugWithTitles('/');
+    $tree = $root->getTreeInfo(false);
+    
+    // launch the rebuild
+    $this->cleanChildren($tree, '/');
+  }
+  
+	private function cleanChildren($tree,$currentPath){
+		foreach($tree as $p)
+	    {
+	    	// Retreive page object
+	    	$page = Doctrine_Query::Create()->
+			      select("p.*")->
+			      from("aPage p")->where('p.id = ?', array($p['id']))->
+			      fetchOne();
+			
+			// New slug based on the page title
+			// Source : BaseaActions.class.php line 205 and 247 (in BaseaActions::executeCreate)
+			$baseSlug = strtolower(preg_replace("/[\W]+/", "-", htmlspecialchars_decode($page->title)));
+			      
+			// children
+			if($page->hasChildren()){
+				$this->cleanChildren($p['children'],$currentPath.$baseSlug.'/');
+			}
+			
+			// save current page's slug
+	    	$page->slug = $currentPath.$baseSlug;
+	    	$page->save();
+		}
+	} 
+}
+
+
+    

