-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redirects now stored in database (needs stress-testing)
- Loading branch information
Showing
13 changed files
with
291 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Craft; | ||
|
||
class Seo_RedirectsController extends BaseController | ||
{ | ||
|
||
public function actionSaveRedirects() | ||
{ | ||
$this->requirePostRequest(); | ||
|
||
if (craft()->seo_redirect->saveAllRedirects(craft()->request->getRequiredPost('data'))) { | ||
craft()->userSession->setNotice(Craft::t('Redirects updated.')); | ||
} else { | ||
craft()->userSession->setError(Craft::t('Couldn’t update redirects.')); | ||
} | ||
|
||
$this->redirectToPostedUrl(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
migrations/m160809_101113_seo_CreateRedirectsAndSitemapsTables.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
namespace Craft; | ||
|
||
/** | ||
* The class name is the UTC timestamp in the format of mYYMMDD_HHMMSS_pluginHandle_migrationName | ||
*/ | ||
class m160809_101113_seo_CreateRedirectsAndSitemapsTables extends BaseMigration | ||
{ | ||
/** | ||
* Any migration code in here is wrapped inside of a transaction. | ||
* | ||
* @return bool | ||
*/ | ||
public function safeUp() | ||
{ | ||
// Create the craft_seo_redirects table | ||
craft()->db->createCommand()->createTable('seo_redirects', array( | ||
'uri' => array('required' => true), | ||
'to' => array('required' => true), | ||
'type' => array('values' => '301,302', 'column' => 'enum', 'required' => true), | ||
), null, true); | ||
|
||
// Create the craft_seo_sitemaps table | ||
craft()->db->createCommand()->createTable('seo_sitemaps', array( | ||
'group' => array('values' => 'sections,categories,customUrls', 'column' => 'enum', 'required' => true), | ||
'url' => array('required' => true), | ||
'frequency' => array('values' => 'always,hourly,daily,weekly,monthly,yearly,never', 'column' => 'enum', 'required' => true), | ||
'priority' => array('maxLength' => 10, 'decimals' => 1, 'required' => true, 'unsigned' => false, 'length' => 11, 'column' => 'decimal'), | ||
), null, true); | ||
|
||
return true; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
migrations/m160809_102830_seo_AddEnabledColumnToSitemapsTable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
namespace Craft; | ||
|
||
/** | ||
* The class name is the UTC timestamp in the format of mYYMMDD_HHMMSS_pluginHandle_migrationName | ||
*/ | ||
class m160809_102830_seo_AddEnabledColumnToSitemapsTable extends BaseMigration | ||
{ | ||
/** | ||
* Any migration code in here is wrapped inside of a transaction. | ||
* | ||
* @return bool | ||
*/ | ||
public function safeUp() | ||
{ | ||
craft()->db->createCommand()->addColumn('seo_sitemaps', 'enabled', AttributeType::Bool); | ||
|
||
$this->_transferData(); | ||
|
||
return true; | ||
} | ||
|
||
private function _transferData() | ||
{ | ||
|
||
// Transfer Redirects | ||
$redirects = craft()->seo->getData('redirects') ? craft()->seo->getData('redirects')['redirects'] : array(); | ||
if (is_string($redirects)) $redirects = json_decode($redirects, true); | ||
|
||
foreach ($redirects as $redirect) | ||
{ | ||
$record = new Seo_RedirectRecord(); | ||
$record->setAttribute('uri', $redirect['uri']); | ||
$record->setAttribute('to', $redirect['to']); | ||
$record->setAttribute('type', $redirect['type']); | ||
$record->save(); | ||
} | ||
|
||
// Transfer Sitemap | ||
$sitemap = craft()->seo->getData('sitemap'); | ||
|
||
// Sections | ||
if (array_key_exists('sections', $sitemap) && !empty($sitemap['sections'])) { | ||
foreach ($sitemap['sections'] as $sectionId => $section) | ||
{ | ||
$record = new Seo_SitemapRecord(); | ||
$record->setAttribute('group', 'sections'); | ||
$record->setAttribute('url', $sectionId); | ||
$record->setAttribute('frequency', $section['frequency']); | ||
$record->setAttribute('priority', $section['priority']); | ||
$record->setAttribute('enabled', $section['enabled']); | ||
$record->save(); | ||
} | ||
} | ||
|
||
// Categories | ||
if (array_key_exists('categories', $sitemap) && !empty($sitemap['categories'])) { | ||
foreach ($sitemap['categories'] as $sectionId => $section) | ||
{ | ||
$record = new Seo_SitemapRecord(); | ||
$record->setAttribute('group', 'categories'); | ||
$record->setAttribute('url', $sectionId); | ||
$record->setAttribute('frequency', $section['frequency']); | ||
$record->setAttribute('priority', $section['priority']); | ||
$record->setAttribute('enabled', $section['enabled']); | ||
$record->save(); | ||
} | ||
} | ||
|
||
// Custom URLS | ||
if (array_key_exists('customUrls', $sitemap) && !empty($sitemap['customUrls'])) { | ||
foreach ($sitemap['customUrls'] as $sectionId => $section) | ||
{ | ||
$record = new Seo_SitemapRecord(); | ||
$record->setAttribute('group', 'customUrls'); | ||
$record->setAttribute('url', $section['url']); | ||
$record->setAttribute('frequency', $section['frequency']); | ||
$record->setAttribute('priority', $section['priority']); | ||
$record->setAttribute('enabled', $section['enabled']); | ||
$record->save(); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Craft; | ||
|
||
class Seo_RedirectRecord extends BaseRecord | ||
{ | ||
/** | ||
* Returns the name of the associated database table. | ||
* | ||
* @return string | ||
*/ | ||
public function getTableName() | ||
{ | ||
return 'seo_redirects'; | ||
} | ||
|
||
public function primaryKey() | ||
{ | ||
return 'id'; | ||
} | ||
|
||
public function defineAttributes() | ||
{ | ||
return [ | ||
'uri' => array(AttributeType::String, 'required' => true), | ||
'to' => array(AttributeType::String, 'required' => true), | ||
'type' => array(AttributeType::Enum, 'values' => "301,302", 'required' => true), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Craft; | ||
|
||
class Seo_SitemapRecord extends BaseRecord | ||
{ | ||
/** | ||
* Returns the name of the associated database table. | ||
* | ||
* @return string | ||
*/ | ||
public function getTableName() | ||
{ | ||
return 'seo_sitemaps'; | ||
} | ||
|
||
public function primaryKey() | ||
{ | ||
return 'id'; | ||
} | ||
|
||
public function defineAttributes() | ||
{ | ||
return [ | ||
'group' => array(AttributeType::Enum, 'values' => "sections,categories,customUrls", 'required' => true), | ||
'url' => array(AttributeType::String, 'required' => true), | ||
'frequency' => array(AttributeType::Enum, 'values' => "always,hourly,daily,weekly,monthly,yearly,never", 'required' => true), | ||
'priority' => array(AttributeType::Number, 'required' => true, 'decimals' => 1), | ||
'enabled' => array(AttributeType::Bool, 'default' => true), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.