PluginProbe
CSS & JavaScript Toolbox / 8.0.3
CSS & JavaScript Toolbox v8.0.3
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
css-javascript-toolbox / includes / installer / upgrade / upgrade.class.php

upgrade.class.php in CSS & JavaScript Toolbox 8.0.3, at includes/installer/upgrade/upgrade.class.php

126 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 * @var mixed
35 */
36 protected $templates;
37
38 /**
39 * put your comment there...
40 *
41 */
42 public function __construct() {
43 // Import dependencies!
44 cssJSToolbox::import('includes:installer:upgrade:block.class.php', 'includes:installer:upgrade:template.class.php');
45 // Load blocks into installer iterator!
46 $this->blocks = $this->getBlocksIterator(get_option(self::BLOCKS_POINTER));
47 // Load templates into templates iterator!
48 $driver = cssJSToolbox::getInstance()->getDBDriver();
49 $templates = $driver->select('SELECT title as `name`, type, `code` FROM ' . self::TEMPLATES_TABLE . ';', ARRAY_A);
50 $this->templates = new CJTInstallerTemplate($templates);
51 }
52
53 /**
54 * put your comment there...
55 *
56 */
57 public function blocks() {
58 $defaultOrder = array();
59 // Upgrade all blocks.
60 foreach ($this->blocks as $index => $block) {
61 // In case the user is never re-ordered the blocks then
62 // the blocks order is not saved in the meta table
63 // however use the blocks order instead!
64 $defaultOrder[] = 'cjtoolbox-' . ($index + 1);
65 // No customization neede, just upgrade!
66 $this->blocks->upgrade();
67 }
68 // Process DB Driver queue!
69 $this->blocks->model->save();
70 // Version 0.2 and 0.3 use wrong algorithm for saving blocks order!
71 // Every version has its owen blocks order however the orders is not used to output the blocks!
72 // Version 1.0 still has argument about this but for simplification sake and for time save
73 // We just get orders from current runnign user! This is not 100% correct but we just need to advice
74 // to install the Plugin using the same author you need to inherits the order from!
75 $blocksPageSlug = CJTPlugin::PLUGIN_REQUEST_ID;
76 // Get current logged-in user order!
77 $order = get_user_option("meta-box-order_settings_page_{$blocksPageSlug}");
78 // Save it into GLOBAL/SHARED option to centralized all users!
79 if (!$order && !empty($defaultOrder)) {
80 $order = array('normal' => implode(',', $defaultOrder));
81 }
82 $this->blocks->model->setOrder($order);
83 // Sync closed block metaboxes!
84 $closedBlocks = get_user_meta(get_current_user_id(), "closedpostboxes_settings_page_{$blocksPageSlug}", true);
85 update_user_meta(get_current_user_id(), "closedpostboxes_{$blocksPageSlug}", $closedBlocks);
86 return true;
87 }
88
89 /**
90 * put your comment there...
91 *
92 */
93 public function finalize() {
94 // Delete old blocks data!
95 delete_option(self::BLOCKS_POINTER);
96 // Drop cjdata table as is it no longed needed!
97 $driver = cssJSToolbox::getInstance()->getDBDriver();
98 $driver->exec('DROP TABLE #__cjtoolbox_cjdata;');
99 // Clean up metabox meta data!
100 $orderUserMetaKey = 'meta-box-order_settings_page_' . CJTPlugin::PLUGIN_REQUEST_ID;
101 $closedUserMetaKey = 'closedpostboxes_settings_page_' . CJTPlugin::PLUGIN_REQUEST_ID;
102 $driver->exec("DELETE FROM #__wordpress_usermeta WHERE meta_key IN ('{$orderUserMetaKey}', '{$closedUserMetaKey}');");
103 return $this;
104 }
105
106 /**
107 * put your comment there...
108 *
109 * @param mixed $blocks
110 */
111 protected abstract function getBlocksIterator($blocks);
112
113 /**
114 * put your comment there...
115 *
116 */
117 public function templates() {
118 // Tranform templates to the new table!
119 foreach ($this->templates as $template) {
120 $this->templates->upgrade();
121 }
122 // Chaining!
123 return $this;
124 }
125
126 } // End class.