adapters
3 days ago
adapter.php
3 days ago
factory.php
3 days ago
index.html
3 days ago
rule.php
3 days ago
urihandler.php
3 days ago
rule.php
83 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | /** |
| 15 | * Update rule abstract class. |
| 16 | * |
| 17 | * @since 1.7 |
| 18 | */ |
| 19 | abstract class VAPUpdateRule |
| 20 | { |
| 21 | /** |
| 22 | * Method run during update process. |
| 23 | * |
| 24 | * @param mixed $parent The parent that calls this method. |
| 25 | * |
| 26 | * @return boolean True on success, otherwise false to stop the flow. |
| 27 | */ |
| 28 | final public function launch($parent) |
| 29 | { |
| 30 | // invoke run method declared by the implementors |
| 31 | $result = $this->run($parent); |
| 32 | |
| 33 | if ($result !== false) |
| 34 | { |
| 35 | // auto-flag task as completed |
| 36 | $this->complete(); |
| 37 | } |
| 38 | |
| 39 | return $result; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Method run during update process. |
| 44 | * |
| 45 | * @param mixed $parent The parent that calls this method. |
| 46 | * |
| 47 | * @return boolean True on success, otherwise false to stop the flow. |
| 48 | */ |
| 49 | abstract protected function run($parent); |
| 50 | |
| 51 | /** |
| 52 | * Children classes can override this method to avoid executing the |
| 53 | * same rule more than once. |
| 54 | * |
| 55 | * @return boolean True to skip the rule execution. |
| 56 | */ |
| 57 | public function did() |
| 58 | { |
| 59 | // get pool of completed tasks |
| 60 | $tasks = VAPFactory::getConfig()->getArray('updatetasks', array()); |
| 61 | // check whether this rule is contained within the list |
| 62 | return in_array(strtolower(get_class($this)), $tasks); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Marks the task as completed. |
| 67 | * Children classes can invoke this method at the end of the run |
| 68 | * in order to prevent a double execution. |
| 69 | * |
| 70 | * @return void |
| 71 | */ |
| 72 | protected function complete() |
| 73 | { |
| 74 | $config = VAPFactory::getConfig(); |
| 75 | |
| 76 | // get pool of completed tasks |
| 77 | $tasks = $config->getArray('updatetasks', array()); |
| 78 | // register this task within the list to mark it as completed |
| 79 | $tasks[] = strtolower(get_class($this)); |
| 80 | $config->set('updatetasks', $tasks); |
| 81 | } |
| 82 | } |
| 83 |