Author: Jonathan.Wage
Date: 2010-01-30 01:26:36 +0100 (Sat, 30 Jan 2010)
New Revision: 27315
Added:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/modules/sympal_redirecter/
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/modules/sympal_redirecter/actions/
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/modules/sympal_redirecter/actions/actions.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/modules/sympal_redirecter/lib/
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/modules/sympal_redirecter/lib/Basesympal_redirecterActions.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/modules/sympal_redirecter/templates/
Modified:
plugins/sfSympalPlugin/trunk/config/routing.yml
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalRedirect.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_content_slots/lib/Basesympal_content_slotsActions.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/sfSympalContentActionLoader.class.php
plugins/sfSympalPlugin/trunk/lib/sfSympalConfiguration.class.php
plugins/sfSympalPlugin/trunk/lib/sfSympalRedirecter.class.php
plugins/sfSympalPlugin/trunk/lib/util/sfSympalFormToolkit.class.php
plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php
plugins/sfSympalPlugin/trunk/modules/sympal_default/lib/Basesympal_defaultActions.class.php
plugins/sfSympalPlugin/trunk/test/fixtures/project/apps/sympal/config/routing.yml
plugins/sfSympalPlugin/trunk/test/fixtures/project/apps/sympal/modules/test/actions/actions.class.php
plugins/sfSympalPlugin/trunk/test/fixtures/project/lib/sfSympalTestFunctional.class.php
plugins/sfSympalPlugin/trunk/test/functional/RedirectsTest.php
plugins/sfSympalPlugin/trunk/test/unit/ConfigurationTest.php
Log:
[1.4][sfSympalPlugin][1.0] Enhancing 404 redirects to allow redirecting of
whole routes
Modified: plugins/sfSympalPlugin/trunk/config/routing.yml
===================================================================
--- plugins/sfSympalPlugin/trunk/config/routing.yml 2010-01-29 21:00:08 UTC
(rev 27314)
+++ plugins/sfSympalPlugin/trunk/config/routing.yml 2010-01-30 00:26:36 UTC
(rev 27315)
@@ -1,5 +1,7 @@
-<?php echo sfSympalToolkit::getRoutesYaml() ?>
+<?php echo sfSympalToolkit::getContentRoutesYaml() ?>
+<?php echo sfSympalToolkit::getRedirectRoutesYaml() ?>
+
sympal_change_language_form:
url: /change_language
param: { module: sympal_default, action: change_language }
Modified:
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalRedirect.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalRedirect.class.php
2010-01-29 21:00:08 UTC (rev 27314)
+++
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalRedirect.class.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -18,4 +18,44 @@
$this->source = $this->source[0] == '/' ? $this->source :
'/'.$this->source;
}
+
+ public function getDestinationType()
+ {
+ if ($this->isDestinationUrl())
+ {
+ return 'url';
+ }
+ else if ($this->isDestinationRoute())
+ {
+ return 'route';
+ }
+ else if ($this->isDestinationPath())
+ {
+ return 'path';
+ }
+ else if ($this->isDestinationContent())
+ {
+ return 'content';
+ }
+ }
+
+ public function isDestinationUrl()
+ {
+ return substr($this->destination, 0, 3) ==='http' ? true : false;
+ }
+
+ public function isDestinationRoute()
+ {
+ return $this->destination && $this->destination[0] === '@' ? true : false;
+ }
+
+ public function isDestinationPath()
+ {
+ return $this->destination[0] === '/' ? true : false;
+ }
+
+ public function isDestinationContent()
+ {
+ return $this->content_id ? true : false;
+ }
}
\ No newline at end of file
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_content_slots/lib/Basesympal_content_slotsActions.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_content_slots/lib/Basesympal_content_slotsActions.class.php
2010-01-29 21:00:08 UTC (rev 27314)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_content_slots/lib/Basesympal_content_slotsActions.class.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -2,4 +2,15 @@
class Basesympal_content_slotsActions extends autoSympal_content_slotsActions
{
+ public function preExecute()
+ {
+ parent::preExecute();
+
+ $this->getContext()->getEventDispatcher()->connect('admin.save_object',
array($this, 'listenToAdminSaveObject'));
+ }
+
+ public function listenToAdminSaveObject(sfEvent $event)
+ {
+ $this->clearCache();
+ }
}
\ No newline at end of file
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/sfSympalContentActionLoader.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/sfSympalContentActionLoader.class.php
2010-01-29 21:00:08 UTC (rev 27314)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/sfSympalContentActionLoader.class.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -198,9 +198,6 @@
$this->_actions->forward('sympal_default', 'new_site');
}
- $redirecter = new sfSympalRedirecter($this->_actions);
- $redirecter->redirect();
-
$this->_actions->forward404();
}
}
Added:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/modules/sympal_redirecter/actions/actions.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/modules/sympal_redirecter/actions/actions.class.php
(rev 0)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/modules/sympal_redirecter/actions/actions.class.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -0,0 +1,15 @@
+<?php
+
+require_once
dirname(__FILE__).'/../lib/Basesympal_redirecterActions.class.php';
+
+/**
+ * sympal_redirecter actions.
+ *
+ * @package sfSympalRenderingPlugin
+ * @subpackage sympal_redirecter
+ * @author Your name here
+ * @version SVN: $Id: actions.class.php 12534 2008-11-01 13:38:27Z
Kris.Wallsmith $
+ */
+class sympal_redirecterActions extends Basesympal_redirecterActions
+{
+}
Added:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/modules/sympal_redirecter/lib/Basesympal_redirecterActions.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/modules/sympal_redirecter/lib/Basesympal_redirecterActions.class.php
(rev 0)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/modules/sympal_redirecter/lib/Basesympal_redirecterActions.class.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -0,0 +1,18 @@
+<?php
+
+/**
+ * Base actions for the sfSympalRenderingPlugin sympal_redirecter module.
+ *
+ * @package sfSympalRenderingPlugin
+ * @subpackage sympal_redirecter
+ * @author Your name here
+ * @version SVN: $Id: BaseActions.class.php 12534 2008-11-01 13:38:27Z
Kris.Wallsmith $
+ */
+abstract class Basesympal_redirecterActions extends sfActions
+{
+ public function executeIndex()
+ {
+ $redirecter = new sfSympalRedirecter($this);
+ $redirecter->redirect();
+ }
+}
Modified: plugins/sfSympalPlugin/trunk/lib/sfSympalConfiguration.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/sfSympalConfiguration.class.php
2010-01-29 21:00:08 UTC (rev 27314)
+++ plugins/sfSympalPlugin/trunk/lib/sfSympalConfiguration.class.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -50,7 +50,6 @@
$this->_dispatcher->connect('form.method_not_found', array(new
sfSympalForm(), 'extend'));
$this->_dispatcher->connect('form.post_configure', array('sfSympalForm',
'listenToFormPostConfigure'));
$this->_dispatcher->connect('form.filter_values', array('sfSympalForm',
'listenToFormFilterValues'));
- $this->_dispatcher->connect('routing.load_configuration', array($this,
'listenToRoutingLoadConfiguration'));
if (sfSympalConfig::get('page_cache', 'super') &&
sfConfig::get('sf_cache'))
{
@@ -77,15 +76,6 @@
}
}
- public function listenToRoutingLoadConfiguration(sfEvent $event)
- {
- // Append route at end to catch all
- $event->getSubject()->appendRoute('sympal_default', new sfRoute('/*',
array(
- 'module' => 'sympal_default',
- 'action' => 'default'
- )));
- }
-
/**
* Callable attached to Symfony event context.load_factories. When this event
* is triggered we also create the Sympal context.
@@ -266,6 +256,10 @@
public function isAdminModule()
{
+ if (!$this->_symfonyContext)
+ {
+ return false;
+ }
$module = $this->_symfonyContext->getRequest()->getParameter('module');
$adminModules = sfSympalConfig::get('admin_modules');
return array_key_exists($module, $adminModules);
Modified: plugins/sfSympalPlugin/trunk/lib/sfSympalRedirecter.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/sfSympalRedirecter.class.php
2010-01-29 21:00:08 UTC (rev 27314)
+++ plugins/sfSympalPlugin/trunk/lib/sfSympalRedirecter.class.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -2,41 +2,69 @@
class sfSympalRedirecter
{
- private $_actions;
+ private
+ $_actions,
+ $_redirect,
+ $_destinationRoute;
public function __construct(sfActions $actions)
{
$this->_actions = $actions;
+ $this->_redirect = Doctrine_Core::getTable('sfSympalRedirect')->find(
+ $this->_actions->getRequest()->getParameter('id')
+ );
}
- public function getRedirect()
+ public function redirect()
{
- return Doctrine_Core::getTable('sfSympalRedirect')
- ->createQuery('r')
- ->leftJoin('r.Content c')
- ->leftJoin('c.Type t')
- ->where('r.source = ?', $this->_actions->getRequest()->getPathInfo())
- ->andWhere('r.site_id = ?',
$this->_actions->getSympalContext()->getSite()->getId())
- ->fetchOne();
+ $this->_actions->redirect($this->_getUrlToRedirectTo());
}
- public function redirect()
+ private function _getDestinationRoute()
{
- if ($redirect = $this->getRedirect())
+ if (!$this->_destinationRoute)
{
- if ($destination = $redirect->getDestination())
+ if ($this->_redirect->isDestinationRoute())
{
- // If the destination is not a url or a symfony route then prefix
- // it with the current requests pathinfo prefix
- if ($destination[0] != '@' && substr($destination, 0, 3) != 'http')
- {
- $destination = trim($destination, '/');
- $destination =
$this->_actions->getRequest()->getPathInfoPrefix().'/'.$destination;
- }
+ $routes = $this->_actions->getContext()->getRouting()->getRoutes();
+ $this->_destinationRoute =
$routes[substr($this->_redirect->getDestination(), 1)];
} else {
- $destination = $redirect->getContent()->getUrl();
+ $this->_destinationRoute = new sfRoute($this->_redirect->destination);
}
- $this->_actions->redirect($destination);
}
+ return $this->_destinationRoute;
}
+
+ private function _getDestinationParameters()
+ {
+ $parameters = array();
+ foreach (array_keys($this->_getDestinationRoute()->getRequirements()) as
$name)
+ {
+ $parameters[$name] = $this->_actions->getRequest()->getParameter($name);
+ }
+ return $parameters;
+ }
+
+ private function _getUrlToRedirectTo()
+ {
+ switch ($this->_redirect->getDestinationType())
+ {
+ case 'url':
+ $destination = $this->_redirect->getDestination();
+ break;
+
+ case 'route':
+ $destination =
$this->_actions->generateUrl(substr($this->_redirect->getDestination(), 1),
$this->_getDestinationParameters());
+ break;
+
+ case 'path':
+ $destination =
$this->_getDestinationRoute()->generate($this->_getDestinationParameters());
+ break;
+
+ case 'content':
+ $destination = $this->_redirect->getContent()->getUrl();
+ break;
+ }
+ return $destination;
+ }
}
\ No newline at end of file
Modified: plugins/sfSympalPlugin/trunk/lib/util/sfSympalFormToolkit.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/util/sfSympalFormToolkit.class.php
2010-01-29 21:00:08 UTC (rev 27314)
+++ plugins/sfSympalPlugin/trunk/lib/util/sfSympalFormToolkit.class.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -47,7 +47,7 @@
} else {
$key = $add;
}
- if (isset($widgetSchema[$key]) || $add)
+ if ((isset($widgetSchema[$key]) && $widgetSchema[$key] instanceof
sfWidgetFormDoctrineChoice) || $add)
{
$q = Doctrine_Core::getTable('sfSympalContent')
->createQuery('c')
Modified: plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php
2010-01-29 21:00:08 UTC (rev 27314)
+++ plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -139,10 +139,10 @@
return $codes;
}
- public static function getRoutesYaml()
+ public static function getRedirectRoutesYaml()
{
- $cachePath =
sfConfig::get('sf_cache_dir').'/'.sfConfig::get('sf_app').'/'.sfConfig::get('sf_environment').'/routes.cache.yml';
- if (file_exists($cachePath))
+ $cachePath =
sfConfig::get('sf_cache_dir').'/'.sfConfig::get('sf_app').'/'.sfConfig::get('sf_environment').'/redirect_routes.cache.yml';
+ if (file_exists($cachePath) && sfConfig::get('sf_environment') !== 'test')
{
return file_get_contents($cachePath);
}
@@ -154,6 +154,50 @@
param:
module: %s
action: %s
+ id: %s
+';
+
+ $routes = array();
+ $siteSlug = sfConfig::get('app_sympal_config_site_slug',
sfConfig::get('sf_app'));
+
+ $redirects = Doctrine::getTable('sfSympalRedirect')
+ ->createQuery('r')
+ ->innerJoin('r.Site s')
+ ->andWhere('s.slug = ?', $siteSlug)
+ ->execute();
+
+ foreach ($redirects as $redirect)
+ {
+ $routes[] = sprintf($routeTemplate,
+ 'sympal_redirect_'.$redirect->getId(),
+ $redirect->getSource(),
+ 'sympal_redirecter',
+ 'index',
+ $redirect->getId()
+ );
+ }
+
+ $routes = implode("\n", $routes);
+ file_put_contents($cachePath, $routes);
+ return $routes;
+ } catch (Exception $e) { }
+ }
+
+ public static function getContentRoutesYaml()
+ {
+ $cachePath =
sfConfig::get('sf_cache_dir').'/'.sfConfig::get('sf_app').'/'.sfConfig::get('sf_environment').'/content_routes.cache.yml';
+ if (file_exists($cachePath) && sfConfig::get('sf_environment') !== 'test')
+ {
+ return file_get_contents($cachePath);
+ }
+
+ try {
+ $routeTemplate =
+'%s:
+ url: %s
+ param:
+ module: %s
+ action: %s
sf_format: html
sympal_content_type: %s
sympal_content_type_id: %s
Modified:
plugins/sfSympalPlugin/trunk/modules/sympal_default/lib/Basesympal_defaultActions.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/modules/sympal_default/lib/Basesympal_defaultActions.class.php
2010-01-29 21:00:08 UTC (rev 27314)
+++
plugins/sfSympalPlugin/trunk/modules/sympal_default/lib/Basesympal_defaultActions.class.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -52,12 +52,4 @@
{
$this->loadSiteTheme();
}
-
- public function executeDefault()
- {
- $redirecter = new sfSympalRedirecter($this);
- $redirecter->redirect();
-
- $this->forward404();
- }
}
\ No newline at end of file
Modified:
plugins/sfSympalPlugin/trunk/test/fixtures/project/apps/sympal/config/routing.yml
===================================================================
---
plugins/sfSympalPlugin/trunk/test/fixtures/project/apps/sympal/config/routing.yml
2010-01-29 21:00:08 UTC (rev 27314)
+++
plugins/sfSympalPlugin/trunk/test/fixtures/project/apps/sympal/config/routing.yml
2010-01-30 00:26:36 UTC (rev 27315)
@@ -21,3 +21,9 @@
change_layout:
url: /test/change_layout
param: { module: test, action: change_layout }
+redirect_route:
+ url: '/test/redirect/:parameter1'
+ param: { module: test, action: redirect }
+redirect_route2:
+ url: '/some/path/ok/:parameter2'
+ param: { module: test, action: redirect }
Modified:
plugins/sfSympalPlugin/trunk/test/fixtures/project/apps/sympal/modules/test/actions/actions.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/test/fixtures/project/apps/sympal/modules/test/actions/actions.class.php
2010-01-29 21:00:08 UTC (rev 27314)
+++
plugins/sfSympalPlugin/trunk/test/fixtures/project/apps/sympal/modules/test/actions/actions.class.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -47,4 +47,9 @@
{
$this->loadTheme('test');
}
+
+ public function executeRedirect()
+ {
+ return sfView::NONE;
+ }
}
\ No newline at end of file
Modified:
plugins/sfSympalPlugin/trunk/test/fixtures/project/lib/sfSympalTestFunctional.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/test/fixtures/project/lib/sfSympalTestFunctional.class.php
2010-01-29 21:00:08 UTC (rev 27314)
+++
plugins/sfSympalPlugin/trunk/test/fixtures/project/lib/sfSympalTestFunctional.class.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -22,4 +22,9 @@
end()
;
}
+
+ public function clearCache()
+ {
+ return
$this->get('/')->getContext()->getController()->getActionStack()->getLastEntry()->getActionInstance()->clearCache();
+ }
}
\ No newline at end of file
Modified: plugins/sfSympalPlugin/trunk/test/functional/RedirectsTest.php
===================================================================
--- plugins/sfSympalPlugin/trunk/test/functional/RedirectsTest.php
2010-01-29 21:00:08 UTC (rev 27314)
+++ plugins/sfSympalPlugin/trunk/test/functional/RedirectsTest.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -6,32 +6,38 @@
$browser = new sfSympalTestFunctional(new sfBrowser());
$redirect = new sfSympalRedirect();
-$redirect->source = '/test_redirect';
-$redirect->destination = '@homepage';
+$redirect->source = '/test_redirect1/:parameter1/ok/:parameter2';
+$redirect->destination = '@redirect_route';
$redirect->site_id = sfSympalContext::getInstance()->getSite()->getId();
$redirect->save();
+$redirect = new sfSympalRedirect();
+$redirect->source = '/test_redirect2';
+$redirect->site_id = sfSympalContext::getInstance()->getSite()->getId();
+$redirect->content_id = 1;
+$redirect->save();
+
+$redirect = new sfSympalRedirect();
+$redirect->source = '/test_redirect3/:parameter1/ok/:parameter2';
+$redirect->destination = '/some/path/ok/:parameter2';
+$redirect->site_id = sfSympalContext::getInstance()->getSite()->getId();
+$redirect->save();
+
+$browser->clearCache();
+
$browser->
- get('/test_redirect')->
+ get('/test_redirect1/test1/ok/test2')->
with('response')->begin()->
isRedirected()->
followRedirect()->
end()->
with('request')->begin()->
- isParameter('module', 'sympal_content_renderer')->
- isParameter('action', 'index')->
- end()->
- with('response')->begin()->
- matches('/Home/')->
+ isParameter('module', 'test')->
+ isParameter('action', 'redirect')->
+ isParameter('parameter1', 'test1')->
end()
;
-$redirect = new sfSympalRedirect();
-$redirect->source = '/test_redirect2';
-$redirect->site_id = sfSympalContext::getInstance()->getSite()->getId();
-$redirect->content_id = 1;
-$redirect->save();
-
$browser->
get('/test_redirect2')->
with('response')->begin()->
@@ -45,4 +51,17 @@
with('response')->begin()->
matches('/Sample Content List/')->
end()
+;
+
+$browser->
+ get('/test_redirect3/test1/ok/test2')->
+ with('response')->begin()->
+ isRedirected()->
+ followRedirect()->
+ end()->
+ with('request')->begin()->
+ isParameter('module', 'test')->
+ isParameter('action', 'redirect')->
+ isParameter('parameter2', 'test2')->
+ end()
;
\ No newline at end of file
Modified: plugins/sfSympalPlugin/trunk/test/unit/ConfigurationTest.php
===================================================================
--- plugins/sfSympalPlugin/trunk/test/unit/ConfigurationTest.php
2010-01-29 21:00:08 UTC (rev 27314)
+++ plugins/sfSympalPlugin/trunk/test/unit/ConfigurationTest.php
2010-01-30 00:26:36 UTC (rev 27315)
@@ -59,7 +59,7 @@
$t->is($sympalConfiguration->getCorePlugins(), $corePlugins);
-$t->is($sympalConfiguration->getInstalledPlugins(), array(
+$t->is(array_values($sympalConfiguration->getInstalledPlugins()), array(
'sfSympalBlogPlugin',
'sfSympalCommentsPlugin',
'sfSympalThemeTestPlugin'
@@ -69,7 +69,7 @@
$t->is(in_array('sfSympalBlogPlugin', $addonPlugins), true);
$t->is(in_array('sfSympalJwageThemePlugin', $addonPlugins), true);
-$t->is($sympalConfiguration->getOtherPlugins(), array(
+$t->is(array_values($sympalConfiguration->getOtherPlugins()), array(
'sfSympalBlogPlugin',
'sfSympalCommentsPlugin',
'sfSympalThemeTestPlugin'
--
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.