@@ -14,17 +14,17 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Constants { |
| 16 | 16 | |
| 17 | - const LIB_NAMESPACE = __NAMESPACE__; |
|
| 17 | + const LIB_NAMESPACE = __NAMESPACE__; |
|
| 18 | 18 | |
| 19 | - /** Internal name of the Certificates Module |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - const MODULE_MAJ_CERTIF_NAME = 'myartjaub_certificates'; |
|
| 19 | + /** Internal name of the Certificates Module |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + const MODULE_MAJ_CERTIF_NAME = 'myartjaub_certificates'; |
|
| 23 | 23 | |
| 24 | - /** Internal name of the GeoDispersion Module |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - const MODULE_MAJ_GEODISP_NAME = 'myartjaub_geodispersion'; |
|
| 24 | + /** Internal name of the GeoDispersion Module |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + const MODULE_MAJ_GEODISP_NAME = 'myartjaub_geodispersion'; |
|
| 28 | 28 | |
| 29 | 29 | /** Internal name of the Hooks Module |
| 30 | 30 | * @var string |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return string $WT_RAPHAEL_JS_URL |
| 62 | 62 | */ |
| 63 | 63 | public static function WT_RAPHAEL_JS_URL() { |
| 64 | - return WT_STATIC_URL . 'packages/raphael-2.1.4/raphael-min.js'; |
|
| 64 | + return WT_STATIC_URL . 'packages/raphael-2.1.4/raphael-min.js'; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | } |
| 68 | 68 | \ No newline at end of file |
@@ -30,11 +30,16 @@ |
||
| 30 | 30 | $place_id = 0; |
| 31 | 31 | for ($i=0; $i<count($parent); $i++) { |
| 32 | 32 | $parent[$i] = trim($parent[$i]); |
| 33 | - if (empty($parent[$i])) $parent[$i]='unknown';// GoogleMap module uses "unknown" while GEDCOM uses , , |
|
| 33 | + if (empty($parent[$i])) { |
|
| 34 | + $parent[$i]='unknown'; |
|
| 35 | + } |
|
| 36 | + // GoogleMap module uses "unknown" while GEDCOM uses , , |
|
| 34 | 37 | $pl_id=Database::prepare('SELECT pl_id FROM `##placelocation` WHERE pl_level=? AND pl_parent_id=? AND pl_place LIKE ? ORDER BY pl_place') |
| 35 | 38 | ->execute(array($i, $place_id, $parent[$i])) |
| 36 | 39 | ->fetchOne(); |
| 37 | - if (empty($pl_id)) break; |
|
| 40 | + if (empty($pl_id)) { |
|
| 41 | + break; |
|
| 42 | + } |
|
| 38 | 43 | $place_id = $pl_id; |
| 39 | 44 | } |
| 40 | 45 | return $place_id; |
@@ -63,8 +63,9 @@ discard block |
||
| 63 | 63 | public function hExtendIndiHeaderIcons(IndividualController $ctrlIndi) { |
| 64 | 64 | if($ctrlIndi){ |
| 65 | 65 | $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
| 66 | - if ($dindi->canDisplayIsSourced()) |
|
| 67 | - return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large'); |
|
| 66 | + if ($dindi->canDisplayIsSourced()) { |
|
| 67 | + return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large'); |
|
| 68 | + } |
|
| 68 | 69 | } |
| 69 | 70 | return ''; |
| 70 | 71 | } |
@@ -97,8 +98,9 @@ discard block |
||
| 97 | 98 | $dindi = new Individual($grec); |
| 98 | 99 | $html .= FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'small'); |
| 99 | 100 | $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1, 'small'); |
| 100 | - if($grec->isDead()) |
|
| 101 | - $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small'); |
|
| 101 | + if($grec->isDead()) { |
|
| 102 | + $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small'); |
|
| 103 | + } |
|
| 102 | 104 | } |
| 103 | 105 | return $html; |
| 104 | 106 | } |
@@ -171,12 +173,13 @@ discard block |
||
| 171 | 173 | </tr>'; |
| 172 | 174 | } |
| 173 | 175 | |
| 174 | - if( $root->isDead() ) |
|
| 175 | - echo ' |
|
| 176 | + if( $root->isDead() ) { |
|
| 177 | + echo ' |
|
| 176 | 178 | <tr> |
| 177 | 179 | <td class="slabel">' . GedcomTag::getLabel('DEAT') . '</td> |
| 178 | 180 | <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1).'</td> |
| 179 | 181 | </tr>'; |
| 182 | + } |
|
| 180 | 183 | |
| 181 | 184 | echo '</table>'; |
| 182 | 185 | } |
@@ -28,29 +28,29 @@ discard block |
||
| 28 | 28 | class IsSourcedModule extends AbstractModule |
| 29 | 29 | implements ModuleSidebarInterface, HookSubscriberInterface, IndividualHeaderExtenderInterface, RecordNameTextExtenderInterface |
| 30 | 30 | { |
| 31 | - /** @var string For custom modules - link for support, upgrades, etc. */ |
|
| 32 | - const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
| 31 | + /** @var string For custom modules - link for support, upgrades, etc. */ |
|
| 32 | + const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * {@inheritDoc} |
|
| 36 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::getTitle() |
|
| 37 | - */ |
|
| 38 | - public function getTitle() { |
|
| 39 | - return I18N::translate('Sourced events'); |
|
| 40 | - } |
|
| 34 | + /** |
|
| 35 | + * {@inheritDoc} |
|
| 36 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::getTitle() |
|
| 37 | + */ |
|
| 38 | + public function getTitle() { |
|
| 39 | + return I18N::translate('Sourced events'); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * {@inheritDoc} |
| 44 | 44 | * @see \Fisharebest\Webtrees\Module\AbstractModule::getDescription() |
| 45 | 45 | */ |
| 46 | - public function getDescription() { |
|
| 47 | - return I18N::translate('Indicate if events related to an record are sourced.'); |
|
| 48 | - } |
|
| 46 | + public function getDescription() { |
|
| 47 | + return I18N::translate('Indicate if events related to an record are sourced.'); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * {@inheritDoc} |
|
| 52 | - * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
| 53 | - */ |
|
| 50 | + /** |
|
| 51 | + * {@inheritDoc} |
|
| 52 | + * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
| 53 | + */ |
|
| 54 | 54 | public function getSubscribedHooks() { |
| 55 | 55 | return array( |
| 56 | 56 | 'hExtendIndiHeaderIcons' => 10, |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface::hExtendIndiHeaderIcons() |
| 64 | 64 | */ |
| 65 | 65 | public function hExtendIndiHeaderIcons(IndividualController $ctrlIndi) { |
| 66 | - if($ctrlIndi){ |
|
| 67 | - $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
|
| 68 | - if ($dindi->canDisplayIsSourced()) |
|
| 69 | - return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large'); |
|
| 70 | - } |
|
| 71 | - return ''; |
|
| 66 | + if($ctrlIndi){ |
|
| 67 | + $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
|
| 68 | + if ($dindi->canDisplayIsSourced()) |
|
| 69 | + return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large'); |
|
| 70 | + } |
|
| 71 | + return ''; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -94,15 +94,15 @@ discard block |
||
| 94 | 94 | * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\RecordNameTextExtenderInterface::hRecordNameAppend() |
| 95 | 95 | */ |
| 96 | 96 | public function hRecordNameAppend(GedcomRecord $grec){ |
| 97 | - $html = ''; |
|
| 98 | - if($grec instanceof \Fisharebest\Webtrees\Individual){ |
|
| 99 | - $dindi = new Individual($grec); |
|
| 100 | - $html .= FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'small'); |
|
| 101 | - $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1, 'small'); |
|
| 102 | - if($grec->isDead()) |
|
| 103 | - $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small'); |
|
| 104 | - } |
|
| 105 | - return $html; |
|
| 97 | + $html = ''; |
|
| 98 | + if($grec instanceof \Fisharebest\Webtrees\Individual){ |
|
| 99 | + $dindi = new Individual($grec); |
|
| 100 | + $html .= FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'small'); |
|
| 101 | + $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1, 'small'); |
|
| 102 | + if($grec->isDead()) |
|
| 103 | + $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small'); |
|
| 104 | + } |
|
| 105 | + return $html; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::defaultSidebarOrder() |
| 111 | 111 | */ |
| 112 | 112 | public function defaultSidebarOrder() { |
| 113 | - return 15; |
|
| 113 | + return 15; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent() |
| 119 | 119 | */ |
| 120 | 120 | public function hasSidebarContent(){ |
| 121 | - return true; |
|
| 121 | + return true; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarAjaxContent() |
| 127 | 127 | */ |
| 128 | 128 | public function getSidebarAjaxContent() { |
| 129 | - return ''; |
|
| 129 | + return ''; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -134,17 +134,17 @@ discard block |
||
| 134 | 134 | * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent() |
| 135 | 135 | */ |
| 136 | 136 | public function getSidebarContent() { |
| 137 | - global $controller; |
|
| 137 | + global $controller; |
|
| 138 | 138 | |
| 139 | - ob_start(); |
|
| 140 | - $root = $controller->getSignificantIndividual(); |
|
| 141 | - if ($root) { |
|
| 142 | - $dindi = new Individual($root); |
|
| 139 | + ob_start(); |
|
| 140 | + $root = $controller->getSignificantIndividual(); |
|
| 141 | + if ($root) { |
|
| 142 | + $dindi = new Individual($root); |
|
| 143 | 143 | |
| 144 | - if (!$dindi->canDisplayIsSourced()) { |
|
| 145 | - echo '<div class="error">', I18N::translate('This information is private and cannot be shown.'), '</div>'; |
|
| 146 | - } else { |
|
| 147 | - echo ' |
|
| 144 | + if (!$dindi->canDisplayIsSourced()) { |
|
| 145 | + echo '<div class="error">', I18N::translate('This information is private and cannot be shown.'), '</div>'; |
|
| 146 | + } else { |
|
| 147 | + echo ' |
|
| 148 | 148 | <table class="issourcedtable"> |
| 149 | 149 | <tr> |
| 150 | 150 | <td class="slabel"> ' . GedcomTag::getLabel('INDI') . '</td> |
@@ -155,35 +155,35 @@ discard block |
||
| 155 | 155 | <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1).'</td> |
| 156 | 156 | </tr>'; |
| 157 | 157 | |
| 158 | - $fams = $root->getSpouseFamilies(); |
|
| 159 | - ($ct = count($fams)) > 1 ? $nb=1 : $nb=' '; |
|
| 160 | - foreach($fams as $fam){ |
|
| 161 | - $dfam = new Family($fam); |
|
| 162 | - echo ' |
|
| 158 | + $fams = $root->getSpouseFamilies(); |
|
| 159 | + ($ct = count($fams)) > 1 ? $nb=1 : $nb=' '; |
|
| 160 | + foreach($fams as $fam){ |
|
| 161 | + $dfam = new Family($fam); |
|
| 162 | + echo ' |
|
| 163 | 163 | <tr> |
| 164 | 164 | <td class="slabel right"> |
| 165 | 165 | <a href="' . $fam->getHtmlUrl() . '"> '. GedcomTag::getLabel('MARR'); |
| 166 | - if($ct > 1){ |
|
| 167 | - echo ' ',$nb; |
|
| 168 | - $nb++; |
|
| 169 | - } |
|
| 170 | - echo ' </a> |
|
| 166 | + if($ct > 1){ |
|
| 167 | + echo ' ',$nb; |
|
| 168 | + $nb++; |
|
| 169 | + } |
|
| 170 | + echo ' </a> |
|
| 171 | 171 | </td> |
| 172 | 172 | <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dfam->isMarriageSourced(), 'MARR', 1).'</td> |
| 173 | 173 | </tr>'; |
| 174 | - } |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - if( $root->isDead() ) |
|
| 177 | - echo ' |
|
| 176 | + if( $root->isDead() ) |
|
| 177 | + echo ' |
|
| 178 | 178 | <tr> |
| 179 | 179 | <td class="slabel">' . GedcomTag::getLabel('DEAT') . '</td> |
| 180 | 180 | <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1).'</td> |
| 181 | 181 | </tr>'; |
| 182 | 182 | |
| 183 | - echo '</table>'; |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - return ob_get_clean(); |
|
| 183 | + echo '</table>'; |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + return ob_get_clean(); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | |
@@ -15,11 +15,11 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | interface ModuleMenuItemInterface |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Returns a menu item for the module. |
|
| 20 | - * |
|
| 21 | - * @param \Fisharebest\Webtrees\Tree|null $tree |
|
| 22 | - * @param mixed $reference |
|
| 23 | - */ |
|
| 24 | - public function getMenu(\Fisharebest\Webtrees\Tree $tree, $reference); |
|
| 18 | + /** |
|
| 19 | + * Returns a menu item for the module. |
|
| 20 | + * |
|
| 21 | + * @param \Fisharebest\Webtrees\Tree|null $tree |
|
| 22 | + * @param mixed $reference |
|
| 23 | + */ |
|
| 24 | + public function getMenu(\Fisharebest\Webtrees\Tree $tree, $reference); |
|
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -35,25 +35,25 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | class TaskController extends MvcController |
| 37 | 37 | { |
| 38 | - /** |
|
| 39 | - * Tasks Provider |
|
| 40 | - * @var TaskProviderInterface $provider |
|
| 41 | - */ |
|
| 42 | - protected $provider; |
|
| 38 | + /** |
|
| 39 | + * Tasks Provider |
|
| 40 | + * @var TaskProviderInterface $provider |
|
| 41 | + */ |
|
| 42 | + protected $provider; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Constructor for Admin Config controller |
|
| 46 | - * @param AbstractModule $module |
|
| 47 | - */ |
|
| 48 | - public function __construct(AbstractModule $module) { |
|
| 49 | - parent::__construct($module); |
|
| 44 | + /** |
|
| 45 | + * Constructor for Admin Config controller |
|
| 46 | + * @param AbstractModule $module |
|
| 47 | + */ |
|
| 48 | + public function __construct(AbstractModule $module) { |
|
| 49 | + parent::__construct($module); |
|
| 50 | 50 | |
| 51 | - $this->provider = $this->module->getProvider(); |
|
| 52 | - } |
|
| 51 | + $this->provider = $this->module->getProvider(); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Pages |
|
| 56 | - */ |
|
| 54 | + /** |
|
| 55 | + * Pages |
|
| 56 | + */ |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Task@trigger |
@@ -77,35 +77,35 @@ discard block |
||
| 77 | 77 | /** |
| 78 | 78 | * Task@setStatus |
| 79 | 79 | */ |
| 80 | - public function setStatus() { |
|
| 81 | - $controller = new JsonController(); |
|
| 80 | + public function setStatus() { |
|
| 81 | + $controller = new JsonController(); |
|
| 82 | 82 | |
| 83 | - $task_name = Filter::get('task'); |
|
| 84 | - $task = $this->provider->getTask($task_name, false); |
|
| 83 | + $task_name = Filter::get('task'); |
|
| 84 | + $task = $this->provider->getTask($task_name, false); |
|
| 85 | 85 | |
| 86 | - $controller->restrictAccess( |
|
| 87 | - true // Filter::checkCsrf() -- Cannot use CSRF on a GET request (modules can only work with GET requests) |
|
| 88 | - && Auth::isAdmin() |
|
| 89 | - && $task |
|
| 90 | - ); |
|
| 86 | + $controller->restrictAccess( |
|
| 87 | + true // Filter::checkCsrf() -- Cannot use CSRF on a GET request (modules can only work with GET requests) |
|
| 88 | + && Auth::isAdmin() |
|
| 89 | + && $task |
|
| 90 | + ); |
|
| 91 | 91 | |
| 92 | - $status = Filter::getBool('status'); |
|
| 93 | - $res = array('task' => $task->getName() , 'error' => null); |
|
| 94 | - try{ |
|
| 95 | - $this->provider->setTaskStatus($task, $status); |
|
| 96 | - $res['status'] = $status; |
|
| 92 | + $status = Filter::getBool('status'); |
|
| 93 | + $res = array('task' => $task->getName() , 'error' => null); |
|
| 94 | + try{ |
|
| 95 | + $this->provider->setTaskStatus($task, $status); |
|
| 96 | + $res['status'] = $status; |
|
| 97 | 97 | Log::addConfigurationLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" has been '. ($status ? 'enabled' : 'disabled') .'.'); |
| 98 | - } |
|
| 99 | - catch (\Exception $ex) { |
|
| 100 | - $res['error'] = $ex->getMessage(); |
|
| 98 | + } |
|
| 99 | + catch (\Exception $ex) { |
|
| 100 | + $res['error'] = $ex->getMessage(); |
|
| 101 | 101 | Log::addErrorLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" could not be ' . ($status ? 'enabled' : 'disabled') .'. Error: '. $ex->getMessage()); |
| 102 | - } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - $controller->pageHeader(); |
|
| 105 | - if($res['error']) http_response_code(500); |
|
| 104 | + $controller->pageHeader(); |
|
| 105 | + if($res['error']) http_response_code(500); |
|
| 106 | 106 | |
| 107 | - echo \Zend_Json::encode($res); |
|
| 108 | - } |
|
| 107 | + echo \Zend_Json::encode($res); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | 111 | * Task@edit |
@@ -113,15 +113,15 @@ discard block |
||
| 113 | 113 | public function edit() { |
| 114 | 114 | global $WT_TREE; |
| 115 | 115 | |
| 116 | - $task_name = Filter::get('task'); |
|
| 117 | - $task = $this->provider->getTask($task_name, false); |
|
| 116 | + $task_name = Filter::get('task'); |
|
| 117 | + $task = $this->provider->getTask($task_name, false); |
|
| 118 | 118 | |
| 119 | - Theme::theme(new AdministrationTheme)->init($WT_TREE); |
|
| 120 | - $controller = new PageController(); |
|
| 121 | - $controller |
|
| 122 | - ->restrictAccess(Auth::isAdmin() && $task) |
|
| 119 | + Theme::theme(new AdministrationTheme)->init($WT_TREE); |
|
| 120 | + $controller = new PageController(); |
|
| 121 | + $controller |
|
| 122 | + ->restrictAccess(Auth::isAdmin() && $task) |
|
| 123 | 123 | ->setPageTitle(I18N::translate('Edit the administrative task')) |
| 124 | - ->addInlineJavascript(' |
|
| 124 | + ->addInlineJavascript(' |
|
| 125 | 125 | function toggleRemainingOccurrences() { |
| 126 | 126 | if($("input:radio[name=\'is_limited\']:checked").val() == 1) { |
| 127 | 127 | $("#nb_occurences").show(); |
@@ -134,39 +134,39 @@ discard block |
||
| 134 | 134 | $("[name=\'is_limited\']").on("change", toggleRemainingOccurrences); |
| 135 | 135 | toggleRemainingOccurrences(); |
| 136 | 136 | ') |
| 137 | - ; |
|
| 137 | + ; |
|
| 138 | 138 | |
| 139 | 139 | |
| 140 | - $data = new ViewBag(); |
|
| 141 | - $data->set('title', $controller->getPageTitle()); |
|
| 140 | + $data = new ViewBag(); |
|
| 141 | + $data->set('title', $controller->getPageTitle()); |
|
| 142 | 142 | $data->set('admin_config_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig&ged=' . $WT_TREE->getNameUrl()); |
| 143 | - $data->set('module_title', $this->module->getTitle()); |
|
| 143 | + $data->set('module_title', $this->module->getTitle()); |
|
| 144 | 144 | $data->set('save_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=Task@save&ged=' . $WT_TREE->getNameUrl()); |
| 145 | 145 | $data->set('task', $task); |
| 146 | 146 | |
| 147 | - ViewFactory::make('TaskEdit', $this, $controller, $data)->render(); |
|
| 147 | + ViewFactory::make('TaskEdit', $this, $controller, $data)->render(); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * Task@save |
| 152 | 152 | */ |
| 153 | 153 | public function save() { |
| 154 | - $tmp_contrl = new PageController(); |
|
| 154 | + $tmp_contrl = new PageController(); |
|
| 155 | 155 | |
| 156 | - $tmp_contrl->restrictAccess( |
|
| 157 | - Auth::isAdmin() |
|
| 158 | - && Filter::checkCsrf() |
|
| 159 | - ); |
|
| 156 | + $tmp_contrl->restrictAccess( |
|
| 157 | + Auth::isAdmin() |
|
| 158 | + && Filter::checkCsrf() |
|
| 159 | + ); |
|
| 160 | 160 | |
| 161 | 161 | $task_name = Filter::post('task'); |
| 162 | - $frequency = Filter::postInteger('frequency'); |
|
| 163 | - $is_limited = Filter::postInteger('is_limited', 0, 1); |
|
| 164 | - $nb_occur = Filter::postInteger('nb_occur'); |
|
| 162 | + $frequency = Filter::postInteger('frequency'); |
|
| 163 | + $is_limited = Filter::postInteger('is_limited', 0, 1); |
|
| 164 | + $nb_occur = Filter::postInteger('nb_occur'); |
|
| 165 | 165 | |
| 166 | 166 | $task = $this->provider->getTask($task_name, false); |
| 167 | 167 | |
| 168 | - $success = false; |
|
| 169 | - if($task) { |
|
| 168 | + $success = false; |
|
| 169 | + if($task) { |
|
| 170 | 170 | $task->setFrequency($frequency); |
| 171 | 171 | if($is_limited == 1) { |
| 172 | 172 | $task->setRemainingOccurrences($nb_occur); |
@@ -198,13 +198,13 @@ discard block |
||
| 198 | 198 | Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'. $task->getName() .'” could not be updated. See error log.'); |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - } |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig'; |
|
| 204 | - if(!$success) { |
|
| 203 | + $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig'; |
|
| 204 | + if(!$success) { |
|
| 205 | 205 | $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=Task@edit&task='. $task->getName(); |
| 206 | - } |
|
| 207 | - header('Location: ' . WT_BASE_URL . $redirection_url); |
|
| 206 | + } |
|
| 207 | + header('Location: ' . WT_BASE_URL . $redirection_url); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | } |
| 211 | 211 | \ No newline at end of file |
@@ -95,14 +95,15 @@ discard block |
||
| 95 | 95 | $this->provider->setTaskStatus($task, $status); |
| 96 | 96 | $res['status'] = $status; |
| 97 | 97 | Log::addConfigurationLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" has been '. ($status ? 'enabled' : 'disabled') .'.'); |
| 98 | - } |
|
| 99 | - catch (\Exception $ex) { |
|
| 98 | + } catch (\Exception $ex) { |
|
| 100 | 99 | $res['error'] = $ex->getMessage(); |
| 101 | 100 | Log::addErrorLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" could not be ' . ($status ? 'enabled' : 'disabled') .'. Error: '. $ex->getMessage()); |
| 102 | 101 | } |
| 103 | 102 | |
| 104 | 103 | $controller->pageHeader(); |
| 105 | - if($res['error']) http_response_code(500); |
|
| 104 | + if($res['error']) { |
|
| 105 | + http_response_code(500); |
|
| 106 | + } |
|
| 106 | 107 | |
| 107 | 108 | echo \Zend_Json::encode($res); |
| 108 | 109 | } |
@@ -170,8 +171,7 @@ discard block |
||
| 170 | 171 | $task->setFrequency($frequency); |
| 171 | 172 | if($is_limited == 1) { |
| 172 | 173 | $task->setRemainingOccurrences($nb_occur); |
| 173 | - } |
|
| 174 | - else { |
|
| 174 | + } else { |
|
| 175 | 175 | $task->setRemainingOccurrences(0); |
| 176 | 176 | } |
| 177 | 177 | |
@@ -192,8 +192,7 @@ discard block |
||
| 192 | 192 | Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'.$task->getName() .'” has been updated.'); |
| 193 | 193 | $success = true; |
| 194 | 194 | } |
| 195 | - } |
|
| 196 | - else { |
|
| 195 | + } else { |
|
| 197 | 196 | FlashMessages::addMessage(I18N::translate('An error occured while updating the administrative task “%s”', $task->getTitle()), 'danger'); |
| 198 | 197 | Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'. $task->getName() .'” could not be updated. See error log.'); |
| 199 | 198 | } |
@@ -236,7 +236,9 @@ discard block |
||
| 236 | 236 | * @return bool |
| 237 | 237 | */ |
| 238 | 238 | public function save() { |
| 239 | - if(!$this->provider) throw new \Exception('The task has not been initialised with a provider.'); |
|
| 239 | + if(!$this->provider) { |
|
| 240 | + throw new \Exception('The task has not been initialised with a provider.'); |
|
| 241 | + } |
|
| 240 | 242 | return $this->provider->updateTask($this); |
| 241 | 243 | } |
| 242 | 244 | |
@@ -246,8 +248,9 @@ discard block |
||
| 246 | 248 | */ |
| 247 | 249 | public function execute(){ |
| 248 | 250 | |
| 249 | - if($this->last_updated->add(new \DateInterval('PT'.self::TASK_TIME_OUT.'S')) < new \DateTime()) |
|
| 250 | - $this->is_running = false; |
|
| 251 | + if($this->last_updated->add(new \DateInterval('PT'.self::TASK_TIME_OUT.'S')) < new \DateTime()) { |
|
| 252 | + $this->is_running = false; |
|
| 253 | + } |
|
| 251 | 254 | |
| 252 | 255 | if(!$this->is_running){ //TODO put in place a time_out for running... |
| 253 | 256 | //TODO Log the executions in the logs |
@@ -261,7 +264,9 @@ discard block |
||
| 261 | 264 | $this->last_updated = new \DateTime(); |
| 262 | 265 | if($this->nb_occurrences > 0){ |
| 263 | 266 | $this->nb_occurrences--; |
| 264 | - if($this->nb_occurrences == 0) $this->is_enabled = false; |
|
| 267 | + if($this->nb_occurrences == 0) { |
|
| 268 | + $this->is_enabled = false; |
|
| 269 | + } |
|
| 265 | 270 | } |
| 266 | 271 | } |
| 267 | 272 | $this->is_running = false; |
@@ -20,253 +20,253 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | abstract class AbstractTask { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Time out for runnign tasks, in seconds. Default 5 min |
|
| 25 | - * @var int TASK_TIME_OUT |
|
| 26 | - */ |
|
| 27 | - const TASK_TIME_OUT = 300; |
|
| 23 | + /** |
|
| 24 | + * Time out for runnign tasks, in seconds. Default 5 min |
|
| 25 | + * @var int TASK_TIME_OUT |
|
| 26 | + */ |
|
| 27 | + const TASK_TIME_OUT = 300; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Task provider |
|
| 31 | - * @var TaskProviderInterface $provider |
|
| 32 | - */ |
|
| 29 | + /** |
|
| 30 | + * Task provider |
|
| 31 | + * @var TaskProviderInterface $provider |
|
| 32 | + */ |
|
| 33 | 33 | protected $provider; |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * Task name |
| 37 | 37 | * @var string $name |
| 38 | 38 | */ |
| 39 | - protected $name; |
|
| 39 | + protected $name; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Status of the task |
|
| 43 | - * @var bool $is_enabled |
|
| 44 | - */ |
|
| 45 | - protected $is_enabled; |
|
| 41 | + /** |
|
| 42 | + * Status of the task |
|
| 43 | + * @var bool $is_enabled |
|
| 44 | + */ |
|
| 45 | + protected $is_enabled; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Last updated date |
|
| 49 | - * @var \DateTime $last_updated |
|
| 50 | - */ |
|
| 51 | - protected $last_updated; |
|
| 47 | + /** |
|
| 48 | + * Last updated date |
|
| 49 | + * @var \DateTime $last_updated |
|
| 50 | + */ |
|
| 51 | + protected $last_updated; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Last run result |
|
| 55 | - * @var bool $last_result |
|
| 56 | - */ |
|
| 57 | - protected $last_result; |
|
| 53 | + /** |
|
| 54 | + * Last run result |
|
| 55 | + * @var bool $last_result |
|
| 56 | + */ |
|
| 57 | + protected $last_result; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Task run frequency |
|
| 61 | - * @var int $frequency |
|
| 62 | - */ |
|
| 63 | - protected $frequency; |
|
| 59 | + /** |
|
| 60 | + * Task run frequency |
|
| 61 | + * @var int $frequency |
|
| 62 | + */ |
|
| 63 | + protected $frequency; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Task remaining runs |
|
| 67 | - * @var int $nb_occurrences |
|
| 68 | - */ |
|
| 69 | - protected $nb_occurrences; |
|
| 65 | + /** |
|
| 66 | + * Task remaining runs |
|
| 67 | + * @var int $nb_occurrences |
|
| 68 | + */ |
|
| 69 | + protected $nb_occurrences; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Current running status of the task |
|
| 73 | - * @var bool $is_running |
|
| 74 | - */ |
|
| 75 | - protected $is_running; |
|
| 71 | + /** |
|
| 72 | + * Current running status of the task |
|
| 73 | + * @var bool $is_running |
|
| 74 | + */ |
|
| 75 | + protected $is_running; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Constructor for the Admin task class |
|
| 77 | + /** |
|
| 78 | + * Constructor for the Admin task class |
|
| 79 | 79 | * |
| 80 | 80 | * @param string $file Filename containing the task object |
| 81 | 81 | * @param TaskProviderInterface $provider Provider for tasks |
| 82 | - */ |
|
| 83 | - public function __construct($file, TaskProviderInterface $provider = null){ |
|
| 84 | - $this->name = trim(basename($file, '.php')); |
|
| 82 | + */ |
|
| 83 | + public function __construct($file, TaskProviderInterface $provider = null){ |
|
| 84 | + $this->name = trim(basename($file, '.php')); |
|
| 85 | 85 | $this->provider = $provider; |
| 86 | - } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Get the provider. |
|
| 90 | - * |
|
| 91 | - * @return TaskProviderInterface |
|
| 92 | - */ |
|
| 93 | - public function getProvider(){ |
|
| 94 | - return $this->provider; |
|
| 95 | - } |
|
| 88 | + /** |
|
| 89 | + * Get the provider. |
|
| 90 | + * |
|
| 91 | + * @return TaskProviderInterface |
|
| 92 | + */ |
|
| 93 | + public function getProvider(){ |
|
| 94 | + return $this->provider; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Set the provider. |
|
| 99 | - * |
|
| 100 | - * @param TaskProviderInterface $provider |
|
| 101 | - * @return self Enable method-chaining |
|
| 102 | - */ |
|
| 103 | - public function setProvider(TaskProviderInterface $provider){ |
|
| 104 | - $this->provider = $provider; |
|
| 105 | - return $this; |
|
| 106 | - } |
|
| 97 | + /** |
|
| 98 | + * Set the provider. |
|
| 99 | + * |
|
| 100 | + * @param TaskProviderInterface $provider |
|
| 101 | + * @return self Enable method-chaining |
|
| 102 | + */ |
|
| 103 | + public function setProvider(TaskProviderInterface $provider){ |
|
| 104 | + $this->provider = $provider; |
|
| 105 | + return $this; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Set parameters of the Task |
|
| 110 | - * |
|
| 111 | - * @param bool $is_enabled Status of the task |
|
| 112 | - * @param \DateTime $lastupdated Time of the last task run |
|
| 113 | - * @param bool $last_result Result of the last run, true for success, false for failure |
|
| 114 | - * @param int $frequency Frequency of execution in minutes |
|
| 115 | - * @param int $nb_occur Number of remaining occurrences, 0 for tasks not limited |
|
| 116 | - * @param bool $is_running Indicates if the task is currently running |
|
| 117 | - */ |
|
| 118 | - public function setParameters($is_enabled, \DateTime $last_updated, $last_result, $frequency, $nb_occur, $is_running){ |
|
| 119 | - $this->is_enabled = $is_enabled; |
|
| 120 | - $this->last_updated = $last_updated; |
|
| 121 | - $this->last_result = $last_result; |
|
| 122 | - $this->frequency = $frequency; |
|
| 123 | - $this->nb_occurrences = $nb_occur; |
|
| 124 | - $this->is_running = $is_running; |
|
| 125 | - } |
|
| 108 | + /** |
|
| 109 | + * Set parameters of the Task |
|
| 110 | + * |
|
| 111 | + * @param bool $is_enabled Status of the task |
|
| 112 | + * @param \DateTime $lastupdated Time of the last task run |
|
| 113 | + * @param bool $last_result Result of the last run, true for success, false for failure |
|
| 114 | + * @param int $frequency Frequency of execution in minutes |
|
| 115 | + * @param int $nb_occur Number of remaining occurrences, 0 for tasks not limited |
|
| 116 | + * @param bool $is_running Indicates if the task is currently running |
|
| 117 | + */ |
|
| 118 | + public function setParameters($is_enabled, \DateTime $last_updated, $last_result, $frequency, $nb_occur, $is_running){ |
|
| 119 | + $this->is_enabled = $is_enabled; |
|
| 120 | + $this->last_updated = $last_updated; |
|
| 121 | + $this->last_result = $last_result; |
|
| 122 | + $this->frequency = $frequency; |
|
| 123 | + $this->nb_occurrences = $nb_occur; |
|
| 124 | + $this->is_running = $is_running; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Get the name of the task |
|
| 129 | - * |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - public function getName(){ |
|
| 133 | - return $this->name; |
|
| 134 | - } |
|
| 127 | + /** |
|
| 128 | + * Get the name of the task |
|
| 129 | + * |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + public function getName(){ |
|
| 133 | + return $this->name; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Return the status of the task in a boolean way |
|
| 139 | - * |
|
| 140 | - * @return boolean True if enabled |
|
| 141 | - */ |
|
| 142 | - public function isEnabled(){ |
|
| 143 | - return $this->is_enabled; |
|
| 144 | - } |
|
| 137 | + /** |
|
| 138 | + * Return the status of the task in a boolean way |
|
| 139 | + * |
|
| 140 | + * @return boolean True if enabled |
|
| 141 | + */ |
|
| 142 | + public function isEnabled(){ |
|
| 143 | + return $this->is_enabled; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Get the last updated time. |
|
| 148 | - * |
|
| 149 | - * @return \DateTime |
|
| 150 | - */ |
|
| 151 | - public function getLastUpdated(){ |
|
| 152 | - return $this->last_updated; |
|
| 153 | - } |
|
| 146 | + /** |
|
| 147 | + * Get the last updated time. |
|
| 148 | + * |
|
| 149 | + * @return \DateTime |
|
| 150 | + */ |
|
| 151 | + public function getLastUpdated(){ |
|
| 152 | + return $this->last_updated; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * Check if the last result has been successful. |
|
| 157 | - * |
|
| 158 | - * @return bool |
|
| 159 | - */ |
|
| 160 | - public function isLastRunSuccess(){ |
|
| 161 | - return $this->last_result; |
|
| 162 | - } |
|
| 155 | + /** |
|
| 156 | + * Check if the last result has been successful. |
|
| 157 | + * |
|
| 158 | + * @return bool |
|
| 159 | + */ |
|
| 160 | + public function isLastRunSuccess(){ |
|
| 161 | + return $this->last_result; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Get the task frequency. |
|
| 166 | - * |
|
| 167 | - * @return int |
|
| 168 | - */ |
|
| 169 | - public function getFrequency(){ |
|
| 170 | - return $this->frequency; |
|
| 171 | - } |
|
| 164 | + /** |
|
| 165 | + * Get the task frequency. |
|
| 166 | + * |
|
| 167 | + * @return int |
|
| 168 | + */ |
|
| 169 | + public function getFrequency(){ |
|
| 170 | + return $this->frequency; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | 173 | /** |
| 174 | - * Set the task frequency. |
|
| 175 | - * |
|
| 174 | + * Set the task frequency. |
|
| 175 | + * |
|
| 176 | 176 | * @param int $frequency |
| 177 | - * @return self Enable method-chaining |
|
| 178 | - */ |
|
| 179 | - public function setFrequency($frequency){ |
|
| 180 | - $this->frequency = $frequency; |
|
| 177 | + * @return self Enable method-chaining |
|
| 178 | + */ |
|
| 179 | + public function setFrequency($frequency){ |
|
| 180 | + $this->frequency = $frequency; |
|
| 181 | 181 | return $this; |
| 182 | - } |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * Get the number of remaining occurrences. |
|
| 186 | - * |
|
| 187 | - * @return int |
|
| 188 | - */ |
|
| 189 | - public function getRemainingOccurrences(){ |
|
| 190 | - return $this->nb_occurrences; |
|
| 191 | - } |
|
| 184 | + /** |
|
| 185 | + * Get the number of remaining occurrences. |
|
| 186 | + * |
|
| 187 | + * @return int |
|
| 188 | + */ |
|
| 189 | + public function getRemainingOccurrences(){ |
|
| 190 | + return $this->nb_occurrences; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | 193 | /** |
| 194 | - * Set the number of remaining occurrences. |
|
| 195 | - * |
|
| 194 | + * Set the number of remaining occurrences. |
|
| 195 | + * |
|
| 196 | 196 | * @param int $nb_occur |
| 197 | - * @return self Enable method-chaining |
|
| 198 | - */ |
|
| 199 | - public function setRemainingOccurrences($nb_occur){ |
|
| 200 | - $this->nb_occurrences = $nb_occur; |
|
| 197 | + * @return self Enable method-chaining |
|
| 198 | + */ |
|
| 199 | + public function setRemainingOccurrences($nb_occur){ |
|
| 200 | + $this->nb_occurrences = $nb_occur; |
|
| 201 | 201 | return $this; |
| 202 | - } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * Check if the task if running. |
|
| 206 | - * |
|
| 207 | - * @return bool |
|
| 208 | - */ |
|
| 209 | - public function isRunning(){ |
|
| 210 | - return $this->is_running; |
|
| 211 | - } |
|
| 204 | + /** |
|
| 205 | + * Check if the task if running. |
|
| 206 | + * |
|
| 207 | + * @return bool |
|
| 208 | + */ |
|
| 209 | + public function isRunning(){ |
|
| 210 | + return $this->is_running; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * Return the name to display for the task |
|
| 216 | - * |
|
| 217 | - * @return string Title for the task |
|
| 218 | - */ |
|
| 219 | - abstract public function getTitle(); |
|
| 214 | + /** |
|
| 215 | + * Return the name to display for the task |
|
| 216 | + * |
|
| 217 | + * @return string Title for the task |
|
| 218 | + */ |
|
| 219 | + abstract public function getTitle(); |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Return the default frequency for the execution of the task |
|
| 223 | - * |
|
| 224 | - * @return int Frequency for the execution of the task |
|
| 225 | - */ |
|
| 226 | - abstract public function getDefaultFrequency(); |
|
| 221 | + /** |
|
| 222 | + * Return the default frequency for the execution of the task |
|
| 223 | + * |
|
| 224 | + * @return int Frequency for the execution of the task |
|
| 225 | + */ |
|
| 226 | + abstract public function getDefaultFrequency(); |
|
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * Execute the task's actions |
|
| 230 | - */ |
|
| 231 | - abstract protected function executeSteps(); |
|
| 228 | + /** |
|
| 229 | + * Execute the task's actions |
|
| 230 | + */ |
|
| 231 | + abstract protected function executeSteps(); |
|
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | 234 | * Persist task state into database. |
| 235 | 235 | * @return bool |
| 236 | 236 | */ |
| 237 | 237 | public function save() { |
| 238 | - if(!$this->provider) throw new \Exception('The task has not been initialised with a provider.'); |
|
| 238 | + if(!$this->provider) throw new \Exception('The task has not been initialised with a provider.'); |
|
| 239 | 239 | return $this->provider->updateTask($this); |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - /** |
|
| 243 | - * Execute the task, default skeleton |
|
| 244 | - * |
|
| 245 | - */ |
|
| 246 | - public function execute(){ |
|
| 242 | + /** |
|
| 243 | + * Execute the task, default skeleton |
|
| 244 | + * |
|
| 245 | + */ |
|
| 246 | + public function execute(){ |
|
| 247 | 247 | |
| 248 | - if($this->last_updated->add(new \DateInterval('PT'.self::TASK_TIME_OUT.'S')) < new \DateTime()) |
|
| 249 | - $this->is_running = false; |
|
| 248 | + if($this->last_updated->add(new \DateInterval('PT'.self::TASK_TIME_OUT.'S')) < new \DateTime()) |
|
| 249 | + $this->is_running = false; |
|
| 250 | 250 | |
| 251 | - if(!$this->is_running){ |
|
| 252 | - $this->last_result = false; |
|
| 253 | - $this->is_running = true; |
|
| 254 | - $this->save(); |
|
| 251 | + if(!$this->is_running){ |
|
| 252 | + $this->last_result = false; |
|
| 253 | + $this->is_running = true; |
|
| 254 | + $this->save(); |
|
| 255 | 255 | |
| 256 | - Log::addDebugLog('Start execution of Admin task: '.$this->getTitle()); |
|
| 257 | - $this->last_result = $this->executeSteps(); |
|
| 258 | - if($this->last_result){ |
|
| 259 | - $this->last_updated = new \DateTime(); |
|
| 260 | - if($this->nb_occurrences > 0){ |
|
| 261 | - $this->nb_occurrences--; |
|
| 262 | - if($this->nb_occurrences == 0) $this->is_enabled = false; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - $this->is_running = false; |
|
| 266 | - $this->save(); |
|
| 267 | - Log::addDebugLog('Execution completed for Admin task: '.$this->getTitle().' - '.($this->last_result ? 'Success' : 'Failure')); |
|
| 268 | - } |
|
| 269 | - } |
|
| 256 | + Log::addDebugLog('Start execution of Admin task: '.$this->getTitle()); |
|
| 257 | + $this->last_result = $this->executeSteps(); |
|
| 258 | + if($this->last_result){ |
|
| 259 | + $this->last_updated = new \DateTime(); |
|
| 260 | + if($this->nb_occurrences > 0){ |
|
| 261 | + $this->nb_occurrences--; |
|
| 262 | + if($this->nb_occurrences == 0) $this->is_enabled = false; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + $this->is_running = false; |
|
| 266 | + $this->save(); |
|
| 267 | + Log::addDebugLog('Execution completed for Admin task: '.$this->getTitle().' - '.($this->last_result ? 'Success' : 'Failure')); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | 271 | |
| 272 | 272 | } |
@@ -15,11 +15,11 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | interface ConfigurableTaskInterface { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Returns the HTML code to display the specific task configuration. |
|
| 20 | - * |
|
| 21 | - * @return string HTML code |
|
| 22 | - */ |
|
| 18 | + /** |
|
| 19 | + * Returns the HTML code to display the specific task configuration. |
|
| 20 | + * |
|
| 21 | + * @return string HTML code |
|
| 22 | + */ |
|
| 23 | 23 | function htmlConfigForm(); |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -37,47 +37,47 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | public function setTaskStatus(AbstractTask $task, $status); |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Update an Admin Task in the database. |
|
| 42 | - * |
|
| 43 | - * @param AbstractTask $task Task to update |
|
| 44 | - * @return bool |
|
| 45 | - */ |
|
| 46 | - function updateTask(AbstractTask $task); |
|
| 40 | + /** |
|
| 41 | + * Update an Admin Task in the database. |
|
| 42 | + * |
|
| 43 | + * @param AbstractTask $task Task to update |
|
| 44 | + * @return bool |
|
| 45 | + */ |
|
| 46 | + function updateTask(AbstractTask $task); |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Delete the task from the database, in a transactional manner. |
|
| 50 | - * |
|
| 51 | - * @param string $task_name Task to delete |
|
| 52 | - */ |
|
| 53 | - public function deleteTask($task_name); |
|
| 48 | + /** |
|
| 49 | + * Delete the task from the database, in a transactional manner. |
|
| 50 | + * |
|
| 51 | + * @param string $task_name Task to delete |
|
| 52 | + */ |
|
| 53 | + public function deleteTask($task_name); |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Returns the number of Admin Tasks (active and inactive). |
|
| 58 | - * |
|
| 59 | - * @return int |
|
| 60 | - */ |
|
| 61 | - public function getTasksCount(); |
|
| 56 | + /** |
|
| 57 | + * Returns the number of Admin Tasks (active and inactive). |
|
| 58 | + * |
|
| 59 | + * @return int |
|
| 60 | + */ |
|
| 61 | + public function getTasksCount(); |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Return the list of Admin Tasks matching specified criterias. |
|
| 65 | - * |
|
| 66 | - * @param string $search Search criteria in analysis description |
|
| 67 | - * @param array $order_by Columns to order by |
|
| 68 | - * @param int $start Offset to start with (for pagination) |
|
| 69 | - * @param int|null $limit Max number of items to return (for pagination) |
|
| 70 | - * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis[] |
|
| 71 | - */ |
|
| 72 | - function getFilteredTasksList($search = null, $order_by = null, $start = 0, $limit = null); |
|
| 63 | + /** |
|
| 64 | + * Return the list of Admin Tasks matching specified criterias. |
|
| 65 | + * |
|
| 66 | + * @param string $search Search criteria in analysis description |
|
| 67 | + * @param array $order_by Columns to order by |
|
| 68 | + * @param int $start Offset to start with (for pagination) |
|
| 69 | + * @param int|null $limit Max number of items to return (for pagination) |
|
| 70 | + * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis[] |
|
| 71 | + */ |
|
| 72 | + function getFilteredTasksList($search = null, $order_by = null, $start = 0, $limit = null); |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Returns the list of tasks that are currently meant to run. |
|
| 76 | - * Tasks to run can be forced, or can be limited to only one. |
|
| 77 | - * |
|
| 78 | - * @param string|null $force Force the enabled tasks to run. |
|
| 79 | - * @param string|null $task_name Name of the specific task to run |
|
| 80 | - */ |
|
| 74 | + /** |
|
| 75 | + * Returns the list of tasks that are currently meant to run. |
|
| 76 | + * Tasks to run can be forced, or can be limited to only one. |
|
| 77 | + * |
|
| 78 | + * @param string|null $force Force the enabled tasks to run. |
|
| 79 | + * @param string|null $task_name Name of the specific task to run |
|
| 80 | + */ |
|
| 81 | 81 | function getTasksToRun($force = false, $task_name = null); |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -20,32 +20,32 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class TaskProvider implements TaskProviderInterface { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Root path of thr folder containing the tasks |
|
| 25 | - * @var string $root_path |
|
| 26 | - */ |
|
| 27 | - protected $root_path; |
|
| 23 | + /** |
|
| 24 | + * Root path of thr folder containing the tasks |
|
| 25 | + * @var string $root_path |
|
| 26 | + */ |
|
| 27 | + protected $root_path; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Constructor for the Task provider |
|
| 31 | - * @param string $root_path |
|
| 32 | - */ |
|
| 33 | - public function __construct($root_path) { |
|
| 34 | - $this->root_path = $root_path; |
|
| 29 | + /** |
|
| 30 | + * Constructor for the Task provider |
|
| 31 | + * @param string $root_path |
|
| 32 | + */ |
|
| 33 | + public function __construct($root_path) { |
|
| 34 | + $this->root_path = $root_path; |
|
| 35 | 35 | $this->all_tasks = null; |
| 36 | - } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Load a task object from a file. |
|
| 40 | - * |
|
| 41 | - * @param string $task_name Name of the task to load. |
|
| 42 | - */ |
|
| 38 | + /** |
|
| 39 | + * Load a task object from a file. |
|
| 40 | + * |
|
| 41 | + * @param string $task_name Name of the task to load. |
|
| 42 | + */ |
|
| 43 | 43 | protected function loadTask($task_name) { |
| 44 | 44 | try { |
| 45 | 45 | if (file_exists($this->root_path . $task_name .'.php')) { |
| 46 | 46 | $task = include $this->root_path . $task_name .'.php'; |
| 47 | 47 | if($task instanceof AbstractTask) { |
| 48 | - $task->setProvider($this); |
|
| 48 | + $task->setProvider($this); |
|
| 49 | 49 | return $task; |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -55,22 +55,22 @@ discard block |
||
| 55 | 55 | return null; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Creates and returns a Task object from a data row. |
|
| 60 | - * The row data is expected to be an array with the indexes: |
|
| 61 | - * - majat_name: task name |
|
| 62 | - * - majat_status: task status |
|
| 63 | - * - majat_last_run: last run time |
|
| 64 | - * - majat_last_result: last run result |
|
| 65 | - * - majat_frequency: run frequency |
|
| 66 | - * - majat_nb_occur: remaining running occurrences |
|
| 67 | - * - majat_running: is task running |
|
| 68 | - * |
|
| 69 | - * @param array $row |
|
| 70 | - * @return AbstractTask|null |
|
| 71 | - */ |
|
| 72 | - protected function loadTaskFromRow($row) { |
|
| 73 | - $task = $this->loadTask($row['majat_name']); |
|
| 58 | + /** |
|
| 59 | + * Creates and returns a Task object from a data row. |
|
| 60 | + * The row data is expected to be an array with the indexes: |
|
| 61 | + * - majat_name: task name |
|
| 62 | + * - majat_status: task status |
|
| 63 | + * - majat_last_run: last run time |
|
| 64 | + * - majat_last_result: last run result |
|
| 65 | + * - majat_frequency: run frequency |
|
| 66 | + * - majat_nb_occur: remaining running occurrences |
|
| 67 | + * - majat_running: is task running |
|
| 68 | + * |
|
| 69 | + * @param array $row |
|
| 70 | + * @return AbstractTask|null |
|
| 71 | + */ |
|
| 72 | + protected function loadTaskFromRow($row) { |
|
| 73 | + $task = $this->loadTask($row['majat_name']); |
|
| 74 | 74 | |
| 75 | 75 | if($task) { |
| 76 | 76 | $task->setParameters( |
@@ -85,99 +85,99 @@ discard block |
||
| 85 | 85 | return $task; |
| 86 | 86 | } |
| 87 | 87 | else { |
| 88 | - $this->deleteTask($row['majat_name']); |
|
| 88 | + $this->deleteTask($row['majat_name']); |
|
| 89 | 89 | } |
| 90 | 90 | return null; |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * {@inheritDoc} |
|
| 95 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskProviderInterface::getTask() |
|
| 96 | - */ |
|
| 97 | - public function getTask($task_name, $only_enabled = true) { |
|
| 98 | - $args = array ( |
|
| 99 | - 'task_name' => $task_name |
|
| 100 | - ); |
|
| 93 | + /** |
|
| 94 | + * {@inheritDoc} |
|
| 95 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskProviderInterface::getTask() |
|
| 96 | + */ |
|
| 97 | + public function getTask($task_name, $only_enabled = true) { |
|
| 98 | + $args = array ( |
|
| 99 | + 'task_name' => $task_name |
|
| 100 | + ); |
|
| 101 | 101 | |
| 102 | - $sql = 'SELECT majat_name, majat_status, majat_last_run, majat_last_result, majat_frequency, majat_nb_occur, majat_running' . |
|
| 103 | - ' FROM `##maj_admintasks`' . |
|
| 104 | - ' WHERE majat_name = :task_name'; |
|
| 105 | - if($only_enabled) { |
|
| 106 | - $sql .= ' AND majat_status = :status'; |
|
| 107 | - $args['status'] = 'enabled'; |
|
| 108 | - } |
|
| 102 | + $sql = 'SELECT majat_name, majat_status, majat_last_run, majat_last_result, majat_frequency, majat_nb_occur, majat_running' . |
|
| 103 | + ' FROM `##maj_admintasks`' . |
|
| 104 | + ' WHERE majat_name = :task_name'; |
|
| 105 | + if($only_enabled) { |
|
| 106 | + $sql .= ' AND majat_status = :status'; |
|
| 107 | + $args['status'] = 'enabled'; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - $task_array = Database::prepare($sql)->execute($args)->fetchOneRow(\PDO::FETCH_ASSOC); |
|
| 110 | + $task_array = Database::prepare($sql)->execute($args)->fetchOneRow(\PDO::FETCH_ASSOC); |
|
| 111 | 111 | |
| 112 | - if($task_array) { |
|
| 113 | - return $this->loadTaskFromRow($task_array); |
|
| 114 | - } |
|
| 112 | + if($task_array) { |
|
| 113 | + return $this->loadTaskFromRow($task_array); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - return null; |
|
| 117 | - } |
|
| 116 | + return null; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * {@inheritDoc} |
| 121 | 121 | * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskProviderInterface::setTaskStatus() |
| 122 | 122 | */ |
| 123 | - public function setTaskStatus(AbstractTask $task, $status) { |
|
| 124 | - Database::prepare( |
|
| 125 | - 'UPDATE `##maj_admintasks`'. |
|
| 126 | - ' SET majat_status = :status'. |
|
| 127 | - ' WHERE majat_name = :name' |
|
| 128 | - )->execute(array( |
|
| 129 | - 'name' => $task->getName(), |
|
| 123 | + public function setTaskStatus(AbstractTask $task, $status) { |
|
| 124 | + Database::prepare( |
|
| 125 | + 'UPDATE `##maj_admintasks`'. |
|
| 126 | + ' SET majat_status = :status'. |
|
| 127 | + ' WHERE majat_name = :name' |
|
| 128 | + )->execute(array( |
|
| 129 | + 'name' => $task->getName(), |
|
| 130 | 130 | 'status' => $status ? 'enabled' : 'disabled' |
| 131 | - )); |
|
| 132 | - } |
|
| 131 | + )); |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | 135 | * {@inheritDoc} |
| 136 | 136 | * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskProviderInterface::updateTask() |
| 137 | 137 | */ |
| 138 | - public function updateTask(AbstractTask $task) { |
|
| 139 | - try{ |
|
| 140 | - Database::prepare( |
|
| 141 | - 'UPDATE `##maj_admintasks`'. |
|
| 142 | - ' SET majat_status = :status,'. |
|
| 143 | - ' majat_last_run = :last_run,'. |
|
| 144 | - ' majat_last_result = :last_result,'. |
|
| 145 | - ' majat_frequency = :frequency,'. |
|
| 146 | - ' majat_nb_occur = :nb_occurrences,'. |
|
| 147 | - ' majat_running = :is_running'. |
|
| 148 | - ' WHERE majat_name = :name' |
|
| 149 | - )->execute(array( |
|
| 150 | - 'name' => $task->getName(), |
|
| 151 | - 'status' => $task->isEnabled() ? 'enabled' : 'disabled', |
|
| 152 | - 'last_run' => $task->getLastUpdated()->format('Y-m-d H:i:s'), |
|
| 153 | - 'last_result' => $task->isLastRunSuccess() ? 1 : 0, |
|
| 154 | - 'frequency' => $task->getFrequency(), |
|
| 155 | - 'nb_occurrences' => $task->getRemainingOccurrences(), |
|
| 156 | - 'is_running' => $task->isRunning() ? 1 : 0 |
|
| 157 | - )); |
|
| 158 | - return true; |
|
| 159 | - } |
|
| 160 | - catch (\Exception $ex) { |
|
| 161 | - Log::addErrorLog(sprintf('Error while updating the Admin Task %s. Exception: %s', $task->getName(), $ex->getMessage())); |
|
| 162 | - return false; |
|
| 163 | - } |
|
| 164 | - } |
|
| 138 | + public function updateTask(AbstractTask $task) { |
|
| 139 | + try{ |
|
| 140 | + Database::prepare( |
|
| 141 | + 'UPDATE `##maj_admintasks`'. |
|
| 142 | + ' SET majat_status = :status,'. |
|
| 143 | + ' majat_last_run = :last_run,'. |
|
| 144 | + ' majat_last_result = :last_result,'. |
|
| 145 | + ' majat_frequency = :frequency,'. |
|
| 146 | + ' majat_nb_occur = :nb_occurrences,'. |
|
| 147 | + ' majat_running = :is_running'. |
|
| 148 | + ' WHERE majat_name = :name' |
|
| 149 | + )->execute(array( |
|
| 150 | + 'name' => $task->getName(), |
|
| 151 | + 'status' => $task->isEnabled() ? 'enabled' : 'disabled', |
|
| 152 | + 'last_run' => $task->getLastUpdated()->format('Y-m-d H:i:s'), |
|
| 153 | + 'last_result' => $task->isLastRunSuccess() ? 1 : 0, |
|
| 154 | + 'frequency' => $task->getFrequency(), |
|
| 155 | + 'nb_occurrences' => $task->getRemainingOccurrences(), |
|
| 156 | + 'is_running' => $task->isRunning() ? 1 : 0 |
|
| 157 | + )); |
|
| 158 | + return true; |
|
| 159 | + } |
|
| 160 | + catch (\Exception $ex) { |
|
| 161 | + Log::addErrorLog(sprintf('Error while updating the Admin Task %s. Exception: %s', $task->getName(), $ex->getMessage())); |
|
| 162 | + return false; |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | 167 | * {@inheritDoc} |
| 168 | 168 | * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskProviderInterface::getTasksCount() |
| 169 | 169 | */ |
| 170 | - public function getTasksCount() { |
|
| 171 | - return Database::prepare( |
|
| 172 | - 'SELECT COUNT(majat_name)' . |
|
| 173 | - ' FROM `##maj_admintasks`' |
|
| 174 | - )->execute()->fetchOne(); |
|
| 175 | - } |
|
| 170 | + public function getTasksCount() { |
|
| 171 | + return Database::prepare( |
|
| 172 | + 'SELECT COUNT(majat_name)' . |
|
| 173 | + ' FROM `##maj_admintasks`' |
|
| 174 | + )->execute()->fetchOne(); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * {@inheritDoc} |
|
| 179 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskProviderInterface::getTasksToRun() |
|
| 180 | - */ |
|
| 177 | + /** |
|
| 178 | + * {@inheritDoc} |
|
| 179 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskProviderInterface::getTasksToRun() |
|
| 180 | + */ |
|
| 181 | 181 | public function getTasksToRun($force = false, $task_name = null) |
| 182 | 182 | { |
| 183 | 183 | $res = array(); |
@@ -206,12 +206,12 @@ discard block |
||
| 206 | 206 | $data = Database::prepare($sql)->execute($args)->fetchAll(\PDO::FETCH_ASSOC); |
| 207 | 207 | |
| 208 | 208 | foreach($data as $task_row) { |
| 209 | - $task = $this->loadTaskFromRow($task_row); |
|
| 209 | + $task = $this->loadTaskFromRow($task_row); |
|
| 210 | 210 | if($task) |
| 211 | 211 | { |
| 212 | 212 | $res[] = $task; |
| 213 | 213 | } |
| 214 | - } |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | 216 | return $res; |
| 217 | 217 | } |
@@ -220,69 +220,69 @@ discard block |
||
| 220 | 220 | * {@inheritDoc} |
| 221 | 221 | * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskProviderInterface::getFilteredTasksList() |
| 222 | 222 | */ |
| 223 | - public function getFilteredTasksList($search = null, $order_by = null, $start = 0, $limit = null){ |
|
| 224 | - $res = array(); |
|
| 223 | + public function getFilteredTasksList($search = null, $order_by = null, $start = 0, $limit = null){ |
|
| 224 | + $res = array(); |
|
| 225 | 225 | |
| 226 | - $sql = 'SELECT majat_name, majat_status, majat_last_run, majat_last_result, majat_frequency, majat_nb_occur, majat_running' . |
|
| 227 | - ' FROM `##maj_admintasks`'; |
|
| 226 | + $sql = 'SELECT majat_name, majat_status, majat_last_run, majat_last_result, majat_frequency, majat_nb_occur, majat_running' . |
|
| 227 | + ' FROM `##maj_admintasks`'; |
|
| 228 | 228 | |
| 229 | - $args = array(); |
|
| 229 | + $args = array(); |
|
| 230 | 230 | |
| 231 | - if ($order_by) { |
|
| 232 | - $sql .= ' ORDER BY '; |
|
| 233 | - $i = 0; |
|
| 234 | - foreach ($order_by as $key => $value) { |
|
| 235 | - if ($i > 0) { |
|
| 236 | - $sql .= ','; |
|
| 237 | - } |
|
| 231 | + if ($order_by) { |
|
| 232 | + $sql .= ' ORDER BY '; |
|
| 233 | + $i = 0; |
|
| 234 | + foreach ($order_by as $key => $value) { |
|
| 235 | + if ($i > 0) { |
|
| 236 | + $sql .= ','; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - switch ($value['dir']) { |
|
| 240 | - case 'asc': |
|
| 241 | - $sql .= $value['column'] . ' ASC '; |
|
| 242 | - break; |
|
| 243 | - case 'desc': |
|
| 244 | - $sql .= $value['column'] . ' DESC '; |
|
| 245 | - break; |
|
| 246 | - } |
|
| 247 | - $i++; |
|
| 248 | - } |
|
| 249 | - } else { |
|
| 250 | - $sql .= ' ORDER BY majat_name ASC'; |
|
| 251 | - } |
|
| 239 | + switch ($value['dir']) { |
|
| 240 | + case 'asc': |
|
| 241 | + $sql .= $value['column'] . ' ASC '; |
|
| 242 | + break; |
|
| 243 | + case 'desc': |
|
| 244 | + $sql .= $value['column'] . ' DESC '; |
|
| 245 | + break; |
|
| 246 | + } |
|
| 247 | + $i++; |
|
| 248 | + } |
|
| 249 | + } else { |
|
| 250 | + $sql .= ' ORDER BY majat_name ASC'; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - if ($limit) { |
|
| 254 | - $sql .= ' LIMIT :limit OFFSET :offset'; |
|
| 255 | - $args['limit'] = $limit; |
|
| 256 | - $args['offset'] = $start; |
|
| 257 | - } |
|
| 253 | + if ($limit) { |
|
| 254 | + $sql .= ' LIMIT :limit OFFSET :offset'; |
|
| 255 | + $args['limit'] = $limit; |
|
| 256 | + $args['offset'] = $start; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - $data = Database::prepare($sql)->execute($args)->fetchAll(\PDO::FETCH_ASSOC); |
|
| 259 | + $data = Database::prepare($sql)->execute($args)->fetchAll(\PDO::FETCH_ASSOC); |
|
| 260 | 260 | |
| 261 | - foreach($data as $ga) { |
|
| 262 | - $task = $this->loadTaskFromRow($ga); |
|
| 261 | + foreach($data as $ga) { |
|
| 262 | + $task = $this->loadTaskFromRow($ga); |
|
| 263 | 263 | if($task && (empty($search) || ($search && strpos($task->getTitle(), $search) !== false))) |
| 264 | 264 | { |
| 265 | 265 | $res[] = $task; |
| 266 | 266 | } |
| 267 | - } |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - return $res; |
|
| 270 | - } |
|
| 269 | + return $res; |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * {inhericDoc} |
|
| 275 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskProviderInterface::getInstalledTasks() |
|
| 276 | - */ |
|
| 273 | + /** |
|
| 274 | + * {inhericDoc} |
|
| 275 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskProviderInterface::getInstalledTasks() |
|
| 276 | + */ |
|
| 277 | 277 | public function getInstalledTasks() { |
| 278 | 278 | $tasks=array(); |
| 279 | 279 | $dir=opendir($this->root_path); |
| 280 | 280 | while (($file=readdir($dir))!==false){ |
| 281 | 281 | try { |
| 282 | - if($file == '.' || $file == '..') continue; |
|
| 282 | + if($file == '.' || $file == '..') continue; |
|
| 283 | 283 | $task = include $this->root_path . $file; |
| 284 | 284 | if($task ) { |
| 285 | - $task->setProvider($this); |
|
| 285 | + $task->setProvider($this); |
|
| 286 | 286 | Database::prepare( |
| 287 | 287 | 'INSERT IGNORE INTO `##maj_admintasks`'. |
| 288 | 288 | ' (majat_name, majat_status, majat_frequency)'. |
@@ -49,8 +49,7 @@ discard block |
||
| 49 | 49 | return $task; |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | - } |
|
| 53 | - catch(\Exception $ex) { } |
|
| 52 | + } catch(\Exception $ex) { } |
|
| 54 | 53 | |
| 55 | 54 | return null; |
| 56 | 55 | } |
@@ -83,8 +82,7 @@ discard block |
||
| 83 | 82 | ); |
| 84 | 83 | |
| 85 | 84 | return $task; |
| 86 | - } |
|
| 87 | - else { |
|
| 85 | + } else { |
|
| 88 | 86 | $this->deleteTask($row['majat_name']); |
| 89 | 87 | } |
| 90 | 88 | return null; |
@@ -156,8 +154,7 @@ discard block |
||
| 156 | 154 | 'is_running' => $task->isRunning() ? 1 : 0 |
| 157 | 155 | )); |
| 158 | 156 | return true; |
| 159 | - } |
|
| 160 | - catch (\Exception $ex) { |
|
| 157 | + } catch (\Exception $ex) { |
|
| 161 | 158 | Log::addErrorLog(sprintf('Error while updating the Admin Task %s. Exception: %s', $task->getName(), $ex->getMessage())); |
| 162 | 159 | return false; |
| 163 | 160 | } |
@@ -279,7 +276,9 @@ discard block |
||
| 279 | 276 | $dir=opendir($this->root_path); |
| 280 | 277 | while (($file=readdir($dir))!==false){ |
| 281 | 278 | try { |
| 282 | - if($file == '.' || $file == '..') continue; |
|
| 279 | + if($file == '.' || $file == '..') { |
|
| 280 | + continue; |
|
| 281 | + } |
|
| 283 | 282 | $task = include $this->root_path . $file; |
| 284 | 283 | if($task ) { |
| 285 | 284 | $task->setProvider($this); |
@@ -294,12 +293,10 @@ discard block |
||
| 294 | 293 | )); |
| 295 | 294 | |
| 296 | 295 | $tasks[] = $task; |
| 297 | - } |
|
| 298 | - else { |
|
| 296 | + } else { |
|
| 299 | 297 | throw new \Exception; |
| 300 | 298 | } |
| 301 | - } |
|
| 302 | - catch (\Exception $ex) { |
|
| 299 | + } catch (\Exception $ex) { |
|
| 303 | 300 | Log::addErrorLog('An error occured while trying to load the task in file ' . $file . '. Exception: ' . $ex->getMessage()); |
| 304 | 301 | } |
| 305 | 302 | } |
@@ -325,8 +322,7 @@ discard block |
||
| 325 | 322 | Log::addConfigurationLog('Admin Task '.$task_name.' has been deleted from disk - deleting it from DB'); |
| 326 | 323 | |
| 327 | 324 | return true; |
| 328 | - } |
|
| 329 | - catch(\Exception $ex) { |
|
| 325 | + } catch(\Exception $ex) { |
|
| 330 | 326 | Database::rollback(); |
| 331 | 327 | |
| 332 | 328 | Log::addErrorLog('An error occurred while deleting Admin Task '.$task_name.'. Exception: '. $ex->getMessage()); |