PreUpdates.php
1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace AIOSEO\Plugin\Common\Main;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* This class contains pre-updates necessary for the next updates class to run.
*
* @since 4.1.5
*/
class PreUpdates {
/**
* Class constructor.
*
* @since 4.1.5
*/
public function __construct() {
// We don't want an AJAX request check here since the plugin might be installed/activated for the first time via AJAX (e.g. EDD/BLC).
// If that's the case, the cache table needs to be created before the activation hook runs.
if ( wp_doing_cron() ) {
return;
}
$lastActiveVersion = aioseo()->internalOptions->internal->lastActiveVersion;
if ( aioseo()->version !== $lastActiveVersion ) {
// Bust the table/columns cache so that we can start the update migrations with a fresh slate.
aioseo()->internalOptions->database->installedTables = '';
}
if ( version_compare( $lastActiveVersion, '4.1.5', '<' ) ) {
$this->createCacheTable();
}
}
/**
* Creates a new aioseo_cache table.
*
* @since 4.1.5
*
* @return void
*/
public function createCacheTable() {
$db = aioseo()->core->db->db;
$charsetCollate = '';
if ( ! empty( $db->charset ) ) {
$charsetCollate .= "DEFAULT CHARACTER SET {$db->charset}";
}
if ( ! empty( $db->collate ) ) {
$charsetCollate .= " COLLATE {$db->collate}";
}
$tableName = aioseo()->core->cache->getTableName();
if ( ! aioseo()->core->db->tableExists( $tableName ) ) {
$tableName = $db->prefix . $tableName;
aioseo()->core->db->execute(
"CREATE TABLE {$tableName} (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`key` varchar(80) NOT NULL,
`value` longtext NOT NULL,
`expiration` datetime NULL,
`created` datetime NOT NULL,
`updated` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY ndx_aioseo_cache_key (`key`),
KEY ndx_aioseo_cache_expiration (`expiration`)
) {$charsetCollate};"
);
}
}
}