| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
// Disallow direct access. |
| 7 |
defined('ABSPATH') or die("Access denied"); |
| 8 |
|
| 9 |
/** |
| 10 |
* |
| 11 |
*/ |
| 12 |
abstract class CJTUpgradeNonTabledVersions extends CJTHookableClass { |
| 13 |
|
| 14 |
/** |
| 15 |
* |
| 16 |
*/ |
| 17 |
const BLOCKS_POINTER = 'cjtoolbox_data'; |
| 18 |
|
| 19 |
/** |
| 20 |
* |
| 21 |
*/ |
| 22 |
const TEMPLATES_TABLE = '#__cjtoolbox_cjdata'; |
| 23 |
|
| 24 |
/** |
| 25 |
* put your comment there... |
| 26 |
* |
| 27 |
* @var mixed |
| 28 |
*/ |
| 29 |
protected $blocks; |
| 30 |
|
| 31 |
/** |
| 32 |
* put your comment there... |
| 33 |
* |
| 34 |
*/ |
| 35 |
public function __construct() { |
| 36 |
// Import dependencies! |
| 37 |
cssJSToolbox::import('includes:installer:upgrade:block.class.php'); |
| 38 |
// Load blocks into installer iterator! |
| 39 |
$this->blocks = $this->getBlocksIterator(get_option(self::BLOCKS_POINTER)); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* put your comment there... |
| 44 |
* |
| 45 |
*/ |
| 46 |
public function blocks() { |
| 47 |
$defaultOrder = array(); |
| 48 |
// Upgrade all blocks. |
| 49 |
foreach ($this->blocks as $index => $block) { |
| 50 |
// In case the user is never re-ordered the blocks then |
| 51 |
// the blocks order is not saved in the meta table |
| 52 |
// however use the blocks order instead! |
| 53 |
$defaultOrder[] = 'cjtoolbox-' . ($index + 1); |
| 54 |
// No customization neede, just upgrade! |
| 55 |
$this->blocks->upgrade(); |
| 56 |
} |
| 57 |
// Process DB Driver queue! |
| 58 |
$this->blocks->model->save(); |
| 59 |
// Version 0.2 and 0.3 use wrong algorithm for saving blocks order! |
| 60 |
// Every version has its owen blocks order however the orders is not used to output the blocks! |
| 61 |
// Version 1.0 still has argument about this but for simplification sake and for time save |
| 62 |
// We just get orders from current runnign user! This is not 100% correct but we just need to advice |
| 63 |
// to install the Plugin using the same author you need to inherits the order from! |
| 64 |
$blocksPageSlug = CJTPlugin::PLUGIN_REQUEST_ID; |
| 65 |
// Get current logged-in user order! |
| 66 |
$order = get_user_option("meta-box-order_settings_page_{$blocksPageSlug}"); |
| 67 |
// Save it into GLOBAL/SHARED option to centralized all users! |
| 68 |
if (!$order && !empty($defaultOrder)) { |
| 69 |
$order = array('normal' => implode(',', $defaultOrder)); |
| 70 |
} |
| 71 |
$this->blocks->model->setOrder($order); |
| 72 |
// Sync closed block metaboxes! |
| 73 |
$closedBlocks = get_user_meta(get_current_user_id(), "closedpostboxes_settings_page_{$blocksPageSlug}", true); |
| 74 |
update_user_meta(get_current_user_id(), "closedpostboxes_{$blocksPageSlug}", $closedBlocks); |
| 75 |
return true; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* put your comment there... |
| 80 |
* |
| 81 |
*/ |
| 82 |
public function finalize() { |
| 83 |
// Delete old blocks data! |
| 84 |
delete_option(self::BLOCKS_POINTER); |
| 85 |
// Drop cjdata table as is it no longed needed! |
| 86 |
$driver = cssJSToolbox::getInstance()->getDBDriver(); |
| 87 |
$driver->exec('DROP TABLE #__cjtoolbox_cjdata;'); |
| 88 |
// Clean up metabox meta data! |
| 89 |
$orderUserMetaKey = 'meta-box-order_settings_page_' . CJTPlugin::PLUGIN_REQUEST_ID; |
| 90 |
$closedUserMetaKey = 'closedpostboxes_settings_page_' . CJTPlugin::PLUGIN_REQUEST_ID; |
| 91 |
$driver->exec("DELETE FROM #__wordpress_usermeta WHERE meta_key IN ('{$orderUserMetaKey}', '{$closedUserMetaKey}');"); |
| 92 |
return $this; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* put your comment there... |
| 97 |
* |
| 98 |
* @param mixed $blocks |
| 99 |
*/ |
| 100 |
protected abstract function getBlocksIterator($blocks); |
| 101 |
|
| 102 |
} // End class. |