From 10da86e3880eaa688e84e82a0967eb1cbfd6045d Mon Sep 17 00:00:00 2001 From: Jarek Rencz Date: Mon, 4 Feb 2013 02:35:40 +0100 Subject: [PATCH 1/7] fixed old markdown helper --- modules/dmBotAdmin/templates/indexSuccess.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/dmBotAdmin/templates/indexSuccess.php b/modules/dmBotAdmin/templates/indexSuccess.php index 64398af..1b74d8f 100755 --- a/modules/dmBotAdmin/templates/indexSuccess.php +++ b/modules/dmBotAdmin/templates/indexSuccess.php @@ -9,7 +9,7 @@ $form->render('.dm_form.list method=get') ) ). - _tag('div.help_box', markdown('Notes: + _tag('div.help_box', _markdown('Notes: - Find some page with the form above, then run the bot to browse them - The time displayed for each page is not the page creation time, but the time required to send the request and receive the response' From effc5e1ca28e76538be7014241eabf0a23c63bca Mon Sep 17 00:00:00 2001 From: Jarek Rencz Date: Mon, 4 Feb 2013 17:35:07 +0100 Subject: [PATCH 2/7] new markdown helper --- modules/dmBotAdmin/templates/indexSuccess.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/dmBotAdmin/templates/indexSuccess.php b/modules/dmBotAdmin/templates/indexSuccess.php index 64398af..1b74d8f 100644 --- a/modules/dmBotAdmin/templates/indexSuccess.php +++ b/modules/dmBotAdmin/templates/indexSuccess.php @@ -9,7 +9,7 @@ $form->render('.dm_form.list method=get') ) ). - _tag('div.help_box', markdown('Notes: + _tag('div.help_box', _markdown('Notes: - Find some page with the form above, then run the bot to browse them - The time displayed for each page is not the page creation time, but the time required to send the request and receive the response' From 764ae93da7991f438383825f4e12676847dd92aa Mon Sep 17 00:00:00 2001 From: Jarek Rencz Date: Thu, 7 Feb 2013 01:37:55 +0100 Subject: [PATCH 3/7] added ability to run bot in CLI --- lib/dmBot.php | 4 +-- task/dmBotTask.php | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 task/dmBotTask.php diff --git a/lib/dmBot.php b/lib/dmBot.php index debd59b..a78b88e 100755 --- a/lib/dmBot.php +++ b/lib/dmBot.php @@ -62,12 +62,12 @@ public function render($options = array()) return $table->render(); } - protected function getPageUrl(DmPage $page) + public function getPageUrl(DmPage $page) { return $this->baseUrl.'/'.$page->_getI18n('slug'); } - protected function getPageStatusCode(DmPage $page) + public function getPageStatusCode(DmPage $page) { $statusCode = 200; diff --git a/task/dmBotTask.php b/task/dmBotTask.php new file mode 100644 index 0000000..3295061 --- /dev/null +++ b/task/dmBotTask.php @@ -0,0 +1,84 @@ + + */ +class dmBotTask extends dmContextTask +{ + public function configure() { + $this->namespace = 'project'; + $this->name = 'bot'; + $this->briefDescription = 'Runs dmBot to check if pages load properly and preload cache'; + $this->addArguments(array( + new sfCommandArgument('site-url', sfCommandArgument::REQUIRED, 'Url of site to browse'), + )); + $this->addOptions(array( + new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'admin'), + new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'prod'), + new sfCommandOption('limit', 'l', sfCommandOption::PARAMETER_OPTIONAL, 'Limit'), + new sfCommandOption('only-active', 'a', sfCommandOption::PARAMETER_OPTIONAL, 'Browse only active pages'), + new sfCommandOption('slug-pattern', 's', sfCommandOption::PARAMETER_OPTIONAL, 'Browse only pages matching given slug'), + new sfCommandOption('title-pattern', 'k', sfCommandOption::PARAMETER_OPTIONAL, 'Browse only pages matching given title'), + new sfCommandOption('name-pattern', 'n', sfCommandOption::PARAMETER_OPTIONAL, 'Browse only pages matching given name'), + new sfCommandOption('verbose', 'v', sfCommandOption::PARAMETER_NONE, 'Complete output'), + )); + } + + public function execute($arguments = array(), $options = array()) + { + + $this->timerStart("bot"); + + $this->withDatabase(); + + if (!is_null($options['limit'])) $botoptions['limit'] = $options['limit']; + if (!is_null($options['only-active'])) $botoptions['only_active'] = $options['only-active']; + if (!is_null($options['slug-pattern'])) $botoptions['slug_pattern'] = $options['slug-pattern']; + if (!is_null($options['name-pattern'])) $botoptions['name_pattern'] = $options['name-pattern']; + if (!is_null($options['title-pattern'])) $botoptions['title_pattern'] = $options['title-pattern']; + + $this->bot = $this + ->getContext() + ->getServiceContainer() + ->setParameter('dm_bot.options', $botoptions) + ->getService('dm_bot') + ->setBaseUrl($arguments['site-url']) + ->init(); + + $this->logSection('bot', $this->bot->getNbPages() . " pages to browse.", null, "COMMENT"); + + foreach($this->bot->getPages() as $index => $page) + { + $url = $this->bot->getPageUrl($page); + $statusCode = $this->bot->getPageStatusCode($page); + + if ($options['verbose']) $this->logSection('bot', 'will be browsing ' . $url, null, "INFO"); + $this->browse($url, $statusCode, $options); + } + + $this->logTimersTotal(); + + } + + private function browse($url, $expectedStatus = 200, $options = array()) + { + $browser = $this->getContext()->getServiceContainer()->getService('web_browser'); + + $browsingTime = $this->timerStart('browse-' . $url); + + $browser->get($url); + + if ($browser->getResponseCode() == $expectedStatus) + { + if ($options['verbose']) $this->logSection('bot', 'got expected status code of ' . $browser->getResponseCode() . ' after ' . round($browsingTime->getElapsedTime()*1000, 2) . "ms", null, "COMMENT"); + } + else + { + $this->logSection('bot', $url . ' got unexpected code of ' . $browser->getResponseCode() . " (expected code was " . $expectedStatus . ")", null, "ERROR"); + } + } + +} From 2bd8628ccc493c9be325b324293167dee8868147 Mon Sep 17 00:00:00 2001 From: Jarek Rencz Date: Thu, 7 Feb 2013 02:04:28 +0100 Subject: [PATCH 4/7] bug fix: task moved to lib --- {task => lib/task}/dmBotTask.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {task => lib/task}/dmBotTask.php (100%) diff --git a/task/dmBotTask.php b/lib/task/dmBotTask.php similarity index 100% rename from task/dmBotTask.php rename to lib/task/dmBotTask.php From 419800431b8ccd094ec0ed30cd631798c4e3f453 Mon Sep 17 00:00:00 2001 From: Jarek Rencz Date: Thu, 7 Feb 2013 02:13:05 +0100 Subject: [PATCH 5/7] bugfix: wrong name --- lib/task/{dmBotTask.php => dmBotTask.class.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/task/{dmBotTask.php => dmBotTask.class.php} (100%) diff --git a/lib/task/dmBotTask.php b/lib/task/dmBotTask.class.php similarity index 100% rename from lib/task/dmBotTask.php rename to lib/task/dmBotTask.class.php From ebc39a16d47d8e670628e1d52182744294ab7494 Mon Sep 17 00:00:00 2001 From: Jarek Rencz Date: Tue, 2 Apr 2013 20:54:39 +0200 Subject: [PATCH 6/7] added credentials for module --- config/dm/modules.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/dm/modules.yml b/config/dm/modules.yml index c123d68..9ffd57d 100755 --- a/config/dm/modules.yml +++ b/config/dm/modules.yml @@ -5,4 +5,5 @@ Tools: dmBot: front: false admin: true - name: Internal Bot \ No newline at end of file + name: Internal Bot + credentials: bot \ No newline at end of file From 28a677d8a523c693ed198bc917f263fa86d0b9e6 Mon Sep 17 00:00:00 2001 From: Jarek Rencz Date: Sat, 6 Apr 2013 15:23:53 +0200 Subject: [PATCH 7/7] fixed issue with errors after stating dmBotTask with no options provided --- lib/task/dmBotTask.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/task/dmBotTask.class.php b/lib/task/dmBotTask.class.php index 3295061..c2179a6 100644 --- a/lib/task/dmBotTask.class.php +++ b/lib/task/dmBotTask.class.php @@ -34,6 +34,8 @@ public function execute($arguments = array(), $options = array()) $this->withDatabase(); + $botoptions = array(); + if (!is_null($options['limit'])) $botoptions['limit'] = $options['limit']; if (!is_null($options['only-active'])) $botoptions['only_active'] = $options['only-active']; if (!is_null($options['slug-pattern'])) $botoptions['slug_pattern'] = $options['slug-pattern'];