Author: Jonathan.Wage
Date: 2010-01-30 07:05:25 +0100 (Sat, 30 Jan 2010)
New Revision: 27318

Added:
   plugins/sfSympalPlugin/trunk/lib/task/sfSympalRedirectRouteTask.class.php
Modified:
   
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalRedirect.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_redirects/config/generator.yml
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_redirects/lib/Basesympal_redirectsActions.class.php
   plugins/sfSympalPlugin/trunk/lib/sfSympalRedirecter.class.php
Log:
[1.4][sfSympalPlugin][1.0] Fixes for sympal redirects and added task to 
redirect routes


Modified: 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalRedirect.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalRedirect.class.php
    2010-01-30 02:04:23 UTC (rev 27317)
+++ 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalRedirect.class.php
    2010-01-30 06:05:25 UTC (rev 27318)
@@ -39,6 +39,16 @@
     }
   }
 
+  public function getDestinationValue()
+  {
+    return $this->getDestinationType() == 'content' ? $this->content_id : 
$this->destination;
+  }
+
+  public function getDestinationText()
+  {
+    return sprintf('Redirecting to %s "%s"', $this->getDestinationType(), 
$this->getDestinationValue());
+  }
+
   public function isDestinationUrl()
   {
     return substr($this->destination, 0, 3) ==='http' ? true : false;
@@ -51,7 +61,7 @@
 
   public function isDestinationPath()
   {
-    return $this->destination[0] === '/' ? true : false;
+    return isset($this->destination[0]) && $this->destination[0] === '/' ? 
true : false;
   }
 
   public function isDestinationContent()

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_redirects/config/generator.yml
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_redirects/config/generator.yml
  2010-01-30 02:04:23 UTC (rev 27317)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_redirects/config/generator.yml
  2010-01-30 06:05:25 UTC (rev 27318)
@@ -15,7 +15,7 @@
       actions: ~
       fields:  ~
       list:
-        display: [source, destination, content_id]
+        display: [=source, destination_text]
       filter:
         display: [source, destination, content_id]
       form:

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_redirects/lib/Basesympal_redirectsActions.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_redirects/lib/Basesympal_redirectsActions.class.php
     2010-01-30 02:04:23 UTC (rev 27317)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_redirects/lib/Basesympal_redirectsActions.class.php
     2010-01-30 06:05:25 UTC (rev 27318)
@@ -13,6 +13,18 @@
  */
 abstract class Basesympal_redirectsActions extends autoSympal_redirectsActions
 {
+  public function preExecute()
+  {
+    parent::preExecute();
+
+    $this->getContext()->getEventDispatcher()->connect('admin.save_object', 
array($this, 'listenToAdminSaveObject'));
+  }
+
+  public function listenToAdminSaveObject(sfEvent $event)
+  {
+    $this->clearCache();
+  }
+
   public function executeCreate(sfWebRequest $request)
   {
     $this->form = $this->configuration->getForm();

Modified: plugins/sfSympalPlugin/trunk/lib/sfSympalRedirecter.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/sfSympalRedirecter.class.php       
2010-01-30 02:04:23 UTC (rev 27317)
+++ plugins/sfSympalPlugin/trunk/lib/sfSympalRedirecter.class.php       
2010-01-30 06:05:25 UTC (rev 27318)
@@ -58,7 +58,7 @@
       break;
 
       case 'path':
-        $destination = 
$this->_getDestinationRoute()->generate($this->_getDestinationParameters());
+        $destination = 
$this->_actions->getRequest()->getPathInfoPrefix().$this->_getDestinationRoute()->generate($this->_getDestinationParameters());
       break;
 
       case 'content':

Added: plugins/sfSympalPlugin/trunk/lib/task/sfSympalRedirectRouteTask.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/task/sfSympalRedirectRouteTask.class.php   
                        (rev 0)
+++ plugins/sfSympalPlugin/trunk/lib/task/sfSympalRedirectRouteTask.class.php   
2010-01-30 06:05:25 UTC (rev 27318)
@@ -0,0 +1,64 @@
+<?php
+
+class sfSympalRedirectRouteTask extends sfSympalBaseTask
+{
+  protected function configure()
+  {
+    $this->addArguments(array(
+      new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The 
application.'),
+      new sfCommandArgument('route', sfCommandArgument::REQUIRED, 'The route 
to redirect.'),
+      new sfCommandArgument('destination', sfCommandArgument::REQUIRED, 'The 
destination to redirect to.'),
+    ));
+
+    $this->addOptions(array(
+      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 
'The environment', 'dev'),
+    ));
+
+    $this->aliases = array();
+    $this->namespace = 'sympal';
+    $this->name = 'redirect-route';
+    $this->briefDescription = 'Redirect a Symfony route to another route, URL 
or path.';
+
+    $this->detailedDescription = <<<EOF
+The [symfony sympal:redirect-route|INFO] task redirects a Symfony route to 
another route, URL or path.
+
+  [./symfony sympal:redirect-route |INFO]
+EOF;
+  }
+
+  /**
+   * @see sfTask
+   */
+  protected function execute($arguments = array(), $options = array())
+  {
+    $context = sfContext::createInstance($this->configuration);
+    $configCache = $context->getConfigCache();
+    $context->getRouting()->loadConfiguration();
+
+    $routes = $context->getRouting()->getRoutes();
+
+    if (!isset($routes[$arguments['route']]))
+    {
+      throw new InvalidArgumentException(sprintf('Could not find route named 
"%s"', $arguments['route']));
+    }
+
+    $redirect = new sfSympalRedirect();
+    $redirect->source = $routes[$arguments['route']]->getPattern();
+
+    if (is_numeric($arguments['destination']))
+    {
+      $this->logSection('sympal', sprintf('Redirecting route "%s" to content 
id "%s"', $routes[$arguments['route']]->getPattern(), 
$arguments['destination']));
+
+      $redirect->content_id = $arguments['destination'];
+    } else {
+      $this->logSection('sympal', sprintf('Redirecting route "%s" to "%s"', 
$routes[$arguments['route']]->getPattern(), $arguments['destination']));
+
+      $redirect->destination = $arguments['destination'];
+    }
+
+    $redirect->Site = 
Doctrine_Core::getTable('sfSympalSite')->findOneBySlug($arguments['application']);
+    $redirect->save();
+
+    $this->clearCache();
+  }
+}
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to