Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
#152 - Fixed database migration and easily separate internal from ext…
Browse files Browse the repository at this point in the history
…ernal links
  • Loading branch information
Tom Janssens committed Dec 30, 2015
1 parent c54dff9 commit c7295e5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
8 changes: 8 additions & 0 deletions application/manager/component/links/controller/link.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected function _actionBootup(Library\CommandContext $context)
$link->status = $this->getStatus($url);
$link->last_checked_on = gmdate('Y-m-d H:i:s');
$link->url = $url;
$link->internal = '1';
$link->title = $this->getTitle($link->url);
$link->police_zone_id = $this->getZone($link->url);
$link->save();
Expand All @@ -47,6 +48,7 @@ protected function _actionCrawl(Library\CommandContext $context)
$link = $this->getObject('com:links.model.links')
->crawled('0')
->status('200')
->internal('1')
->limit('1')
->getRowset()->top();

Expand All @@ -60,6 +62,12 @@ protected function _actionCrawl(Library\CommandContext $context)
if(!$row->load()) {
$row->url = $url['url'];
$row->police_zone_id = $this->getZone($url['url']);

if($this->getZone($url['url'])) {
$row->internal = '1';
} else {
$row->internal = '0';
}
}

$row->status = $this->getStatus($url['url']);
Expand Down
5 changes: 5 additions & 0 deletions component/links/model/links.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct(Library\ObjectConfig $config)

$this->getState()
->insert('crawled', 'int')
->insert('internal', 'int')
->insert('zone', 'string')
->insert('status', 'int');
}
Expand Down Expand Up @@ -57,6 +58,10 @@ protected function _buildQueryWhere(Library\DatabaseQuerySelect $query)
$query->where('tbl.status = :status')->bind(array('status' => $state->status));
}

if(is_numeric($state->internal)) {
$query->where('tbl.internal = :internal')->bind(array('internal' => $state->internal));
}

if(!in_array($site, array('default'))) {
$query->where('tbl.police_zone_id = :zone')->bind(array('zone' => $site));
}
Expand Down
61 changes: 26 additions & 35 deletions scripts/phpmig/migrations/2015/20150427091313_AddComLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,14 @@ class AddComLinks extends Migration
*/
public function up()
{
$this->_queries = <<<EOL
INSERT INTO `extensions` (`extensions_extension_id`, `title`, `name`, `params`, `enabled`)
VALUES
(51, 'Links', 'com_links', '', 1);
";
INSERT INTO `pages` (`pages_page_id`, `pages_menu_id`, `users_group_id`, `title`, `slug`, `link_url`, `link_id`, `type`, `published`, `hidden`, `home`, `extensions_extension_id`, `created_by`, `created_on`, `modified_by`, `modified_on`, `locked_by`, `locked_on`, `access`, `params`)
VALUES
(10, 1, 0, 'Links', 'links', 'option=com_links&view=links', NULL, 'component', 1, 0, 0, 51, 1, '2015-04-27 09:11:25', NULL, NULL, NULL, NULL, 0, '');
INSERT INTO `pages_closures` (`ancestor_id`, `descendant_id`, `level`)
VALUES
(10, 10, 0);
INSERT INTO `pages_orderings` (`pages_page_id`, `title`, `custom`)
VALUES
(10, 00000000005, 00000000005);
EOL;

parent::up();


// All multilingual zones.
$this->getZones()->reset()->where('language', '=', 3);

$this->_queries = <<<END
INSERT INTO `pages` (`pages_page_id`, `pages_menu_id`, `users_group_id`, `title`, `slug`, `link_url`, `link_id`, `type`, `published`, `hidden`, `home`, `extensions_extension_id`, `created_by`, `created_on`, `modified_by`, `modified_on`, `locked_by`, `locked_on`, `access`, `params`)
VALUES
(120, 2, 0, 'Links', 'links', 'option=com_links&view=links', NULL, 'component', 1, 0, 0, 51, 1, '2015-04-27 09:11:25', NULL, NULL, NULL, NULL, 0, '');
(120, 1, 0, 'Links', 'links', 'option=com_links&view=links', NULL, 'component', 1, 0, 0, 51, 1, '2015-04-27 09:11:25', NULL, NULL, NULL, NULL, 0, '');
INSERT INTO `languages_translations` (`languages_translation_id`, `iso_code`, `table`, `row`, `slug`, `status`, `original`, `deleted`)
VALUES
Expand Down Expand Up @@ -84,20 +60,20 @@ public function up()
INSERT INTO `extensions` (`extensions_extension_id`, `title`, `name`, `params`, `enabled`)
VALUES
(6, 'Links', 'com_links', '', 1);
(6, 'Links', 'com_links', '', 1);
";
INSERT INTO `pages` (`pages_page_id`, `pages_menu_id`, `users_group_id`, `title`, `slug`, `link_url`, `link_id`, `type`, `published`, `hidden`, `home`, `extensions_extension_id`, `created_by`, `created_on`, `modified_by`, `modified_on`, `locked_by`, `locked_on`, `access`, `params`)
VALUES
(120, 2, 0, 'Links', 'links', 'option=com_links&view=links', NULL, 'component', 1, 0, 0, 51, 1, '2015-04-27 09:11:25', NULL, NULL, NULL, NULL, 0, '');
(10, 1, 0, 'Links', 'links', 'option=com_links&view=links', NULL, 'component', 1, 0, 0, 6, 1, '2015-04-27 09:11:25', NULL, NULL, NULL, NULL, 0, '');
INSERT INTO `pages_closures` (`ancestor_id`, `descendant_id`, `level`)
VALUES
(9, 120, 1),
(120, 120, 0);
(10, 10, 0);
INSERT INTO `pages_orderings` (`pages_page_id`, `title`, `custom`)
VALUES
(120, 00000000005, 00000000007);
(10, 00000000005, 00000000005);
EOL;

Expand All @@ -116,6 +92,7 @@ public function up()
`url` varchar(255) NOT NULL DEFAULT '',
`status` int(11) NOT NULL DEFAULT '0',
`crawled` tinyint(1) NOT NULL DEFAULT '0',
`internal` tinyint(1) NOT NULL DEFAULT '0',
`created_on` datetime DEFAULT NULL,
`last_crawled_on` datetime DEFAULT NULL,
`last_checked_on` datetime DEFAULT NULL,
Expand All @@ -140,9 +117,7 @@ public function up()
*/
public function down()
{
$this->_queries = "DROP TABLE IF EXISTS `links`;";
$this->_queries .= "DROP TABLE IF EXISTS `links_relations`;";

// All zones.
$this->_queries .= "DELETE FROM `extensions` WHERE `extensions_extension_id` IN ('51');";
$this->_queries .= "DELETE FROM `pages` WHERE `pages_page_id` IN ('120');";

Expand All @@ -155,11 +130,27 @@ public function down()

parent::down();

// All multilingual zones.
// Fed site.
$this->getZones()->where('language', '=', 7);

$this->_queries = "DELETE FROM `fr-be_pages` WHERE `pages_page_id` IN ('120');";
$this->_queries = "DELETE FROM `de-be_pages` WHERE `pages_page_id` IN ('120');";
$this->_queries .= "DELETE FROM `de-be_pages` WHERE `pages_page_id` IN ('120');";

parent::down();

// Target `data` database
$this->getZones()->set(array('data' => 'Data'));

$this->_queries = "ALTER TABLE `users` DROP `links`;";
$this->_queries .= "ALTER TABLE `users` DROP `links_relations`;";

parent::down();

// Target `manager` database
$this->getZones()->set(array('manager' => 'Manager'));

$this->_queries = "DELETE FROM `pages` WHERE `pages_page_id` IN ('10');";
$this->_queries .= "DELETE FROM `extensions` WHERE `extensions_extension_id` IN ('6');";

parent::down();
}
Expand Down

0 comments on commit c7295e5

Please sign in to comment.