| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Tag Groups Pro |
| 5 |
* |
| 6 |
* @package Tag Groups Pro |
| 7 |
* @author Christoph Amthor |
| 8 |
* @copyright 2017 Christoph Amthor (@ Chatty Mango, chattymango.com) |
| 9 |
* @license see official vendor website |
| 10 |
* |
| 11 |
* |
| 12 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 15 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 16 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 18 |
* THE SOFTWARE. |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace, Squiz.Classes.ValidClassName.NotCamelCaps, PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
| 23 |
if (! class_exists('TagGroups_Update')) { |
| 24 |
class TagGroups_Update |
| 25 |
{ |
| 26 |
private $old_version; |
| 27 |
private $new_version; |
| 28 |
|
| 29 |
|
| 30 |
/** |
| 31 |
* |
| 32 |
* @unittest |
| 33 |
* |
| 34 |
* @param string $old_version |
| 35 |
* @param string $new_version |
| 36 |
*/ |
| 37 |
public function __construct($old_version, $new_version) |
| 38 |
{ |
| 39 |
|
| 40 |
$this->old_version = $old_version; |
| 41 |
$this->new_version = $new_version; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
/** |
| 46 |
* Run scripts for specific old or new versions |
| 47 |
* |
| 48 |
* @unittest |
| 49 |
* @return void |
| 50 |
*/ |
| 51 |
public function run_specific_scripts() |
| 52 |
{ |
| 53 |
|
| 54 |
if (empty($this->old_version) || empty($this->new_version)) { |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found |
| 59 |
// if ( version_compare( $this->old_version, '1.18.0' , '<' ) ) { |
| 60 |
// } |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
/** |
| 65 |
* Run processes for all version number steps |
| 66 |
* |
| 67 |
* @param void |
| 68 |
* @return void |
| 69 |
*/ |
| 70 |
public function run_general_scripts() |
| 71 |
{ |
| 72 |
|
| 73 |
/* |
| 74 |
* Taxonomy should not be empty |
| 75 |
*/ |
| 76 |
$tag_group_taxonomy = TagGroups_Options::get_option('tag_group_taxonomy', array()); |
| 77 |
if (empty($tag_group_taxonomy)) { |
| 78 |
update_option('tag_group_taxonomy', array('post_tag')); |
| 79 |
} elseif (! is_array($tag_group_taxonomy)) { |
| 80 |
// Prevent some weird errors |
| 81 |
TagGroups_Options::update_option('tag_group_taxonomy', array( $tag_group_taxonomy )); |
| 82 |
} |
| 83 |
|
| 84 |
/* |
| 85 |
* Theme should not be empty |
| 86 |
*/ |
| 87 |
if ('' == TagGroups_Options::get_option('tag_group_theme', '')) { |
| 88 |
TagGroups_Options::update_option('tag_group_theme', TAG_GROUPS_STANDARD_THEME); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
/** |
| 93 |
* Register time of first use |
| 94 |
*/ |
| 95 |
if (defined('TAG_GROUPS_PLUGIN_IS_FREE') && TAG_GROUPS_PLUGIN_IS_FREE) { |
| 96 |
if (! TagGroups_Options::get_option('tag_group_base_first_activation_time', false)) { |
| 97 |
update_option('tag_group_base_first_activation_time', time()); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
// If requested and new options exist, then remove old options. |
| 103 |
if ( |
| 104 |
defined('TAG_GROUPS_REMOVE_OLD_OPTIONS') |
| 105 |
&& TAG_GROUPS_REMOVE_OLD_OPTIONS |
| 106 |
&& TagGroups_Options::get_option('term_groups', false) |
| 107 |
&& TagGroups_Options::get_option('term_group_positions', false) |
| 108 |
&& TagGroups_Options::get_option('term_group_labels', false) |
| 109 |
) { |
| 110 |
delete_option('tag_group_labels'); |
| 111 |
delete_option('tag_group_ids'); |
| 112 |
delete_option('max_tag_group_id'); |
| 113 |
TagGroups_Error::log('[Tag Groups] Deleted deprecated options'); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
/** |
| 118 |
* Start with some delay so that in the case of simultaneous activation the base plugin will be available |
| 119 |
*/ |
| 120 |
TagGroups_Cron::schedule_in_secs(2, 'tag_groups_check_tag_migration'); |
| 121 |
TagGroups_Cron::schedule_in_secs(500, 'tag_groups_check_if_migrations_done'); |
| 122 |
// long enough after premium tasks |
| 123 |
|
| 124 |
/** |
| 125 |
* Reset the group filter above the tags list |
| 126 |
*/ |
| 127 |
update_option('tag_group_tags_filter', array()); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
/** |
| 132 |
* Update the database entry with the latest version |
| 133 |
* |
| 134 |
* @unittest |
| 135 |
* @return void |
| 136 |
*/ |
| 137 |
public function update_version_number() |
| 138 |
{ |
| 139 |
|
| 140 |
// save new version |
| 141 |
TagGroups_Options::update_option('tag_group_base_version', $this->new_version); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
} |
| 147 |
|