Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Symphony 4.x #24

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions content/content.routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public function __viewIndex() {
$divgroup->appendChild($labelto);

$divcontent = new XMLElement('div');
$divcontent->setAttribute('class', 'content');
$divcontent->appendChild($divgroup);

$recontent = clone $divcontent;
Expand Down Expand Up @@ -109,9 +108,9 @@ public function __viewIndex() {

$header = new XMLElement('header');
$header->appendChild(new XMLElement('h4', $route['type'] == 'redirect' ? __('Redirect') : __('Route') ));
$header->appendChild(new XMLElement('span', __('From'), array('class' => 'type')));
$header->appendChild(new XMLElement('span', $from, array('class' => 'type')));
$header->appendChild(new XMLElement('span', __('To'), array('class' => 'type')));
$header->appendChild(new XMLElement('span', __('From') . ' ', array('class' => 'type')));
$header->appendChild(new XMLElement('span', $from . ' ', array('class' => 'type')));
$header->appendChild(new XMLElement('span', __('To') . ' ', array('class' => 'type')));
$header->appendChild(new XMLElement('span', $to, array('class' => 'type')));

$hidden = Widget::Input("settings[url-router][routes][][type]", $route['type'], 'hidden');
Expand All @@ -122,7 +121,6 @@ public function __viewIndex() {
$li->appendChild($hidden);

$divcontent = new XMLElement('div');
$divcontent->setAttribute('class', 'content');

$divgroup = new XMLElement('div');
$divgroup->setAttribute('class', 'group');
Expand Down Expand Up @@ -168,10 +166,25 @@ public function __viewIndex() {

$this->Form->appendChild($fieldset);

$this->Header->setAttribute('class', 'spaced-bottom');
$this->Context->setAttribute('class', 'spaced-right');
$this->Contents->setAttribute('class', 'centered-content');
$div = new XMLElement('div');
$div->setAttribute('class', 'actions');

$div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', array('accesskey' => 's')));
$div->appendChild(
Widget::SVGIconContainer(
'save',
Widget::Input(
'action[save]',
__('Save Changes'),
'submit',
array('accesskey' => 's')
)
)
);

$div->appendChild(Widget::SVGIcon('chevron'));

$this->Form->appendChild($div);

Expand Down
66 changes: 51 additions & 15 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,32 @@

public function install()
{
Symphony::Database()->query("
CREATE TABLE IF NOT EXISTS `tbl_url_router` (
`id` int(11) NOT NULL auto_increment,
`from` varchar(255) NOT NULL,
`to` varchar(255) NOT NULL,
`type` enum('route','redirect') DEFAULT 'route',
`http301` enum('yes','no') DEFAULT 'no',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
");
return Symphony::Database()
->create('tbl_url_router')
->ifNotExists()
->fields([
'id' => [
'type' => 'int(11)',
'auto' => true,
],
'from' => 'varchar(255)',
'to' => 'varchar(255)',
'type' => [
'type' => 'enum',
'values' => ['route','redirect'],
'default' => 'route',
],
'http301' => [
'type' => 'enum',
'values' => ['yes','no'],
'default' => 'no',
],
])
->keys([
'id' => 'primary',
])
->execute()
->success();
}

public function fetchNavigation() {
Expand All @@ -30,7 +46,11 @@ public function fetchNavigation() {

public function uninstall()
{
return Symphony::Database()->query("DROP TABLE `tbl_url_router`");
return Symphony::Database()
->drop('tbl_url_router')
->ifExists()
->execute()
->success();
}

public function getSubscribedDelegates()
Expand All @@ -51,7 +71,11 @@ public function getSubscribedDelegates()
*/
public function getRoutes()
{
$routes = Symphony::Database()->fetch("SELECT * FROM tbl_url_router");
$routes = Symphony::Database()
->select(['*'])
->from('tbl_url_router')
->execute()
->rows();

foreach ($routes as $i => $route)
{
Expand Down Expand Up @@ -200,14 +224,26 @@ public function saveRoutes()
}
}

Symphony::Database()->query("DELETE FROM tbl_url_router");
Symphony::Database()
->delete('tbl_url_router')
->all()
->finalize()
->execute()
->success();

if(count($routes) > 0) {
Symphony::Database()->insert($routes, "tbl_url_router");
foreach($routes as $route => $values) {
Symphony::Database()
->insert('tbl_url_router')
->values($values)
->execute()
->success();
}

unset($_POST['settings']['url-router']['routes']);
}

redirect(SYMPHONY_URL . '/extension/url_router/routes/index/saved/');
redirect(SYMPHONY_URL . '/extension/url_router/routes/');
}

public function frontendPrePageResolve($context)
Expand Down
4 changes: 4 additions & 0 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
</author>
</authors>
<releases>
<release version="4.0.0" date="TBA" min="4.0.0" max="4.x.x" php-min="5.6.x" php-max="7.x.x">
* Update for Symphony 4.x
* Code refactoring for Database and EQFA
</release>
<release version="3.1" date="2014-10-29" min="2.4" max="2.5.x">
* [#20](https://github.com/symphonists/url_router/issues/20) Fix routing on Symphony 2.4+
* Use `PageManager` instead of internal functions
Expand Down