V3201.php
2.42 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace AC\Plugin\Update;
use AC\Plugin\Update;
use AC\Plugin\Version;
use AC\Preferences;
use DirectoryIterator;
use FilesystemIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
class V3201 extends Update {
public function __construct() {
parent::__construct( new Version( '3.2.1' ) );
}
public function apply_update() {
$this->uppercase_class_files( AC()->get_dir() . '/classes' );
$this->update_notice_preference_review();
$this->update_notice_preference_addons();
}
/**
* Set all files to the proper case
*
* @param string Directory
*/
protected function uppercase_class_files( $directory ) {
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $directory, FilesystemIterator::SKIP_DOTS )
);
/** @var DirectoryIterator $leaf */
foreach ( $iterator as $leaf ) {
$file = $leaf->getFilename();
if ( $leaf->isFile() && 'php' === $leaf->getExtension() && $file == strtolower( $file ) ) {
@rename( $leaf->getPathname(), trailingslashit( $leaf->getPath() ) . ucfirst( $file ) );
}
}
}
/**
* Update user preferences for review
*/
private function update_notice_preference_review() {
$mapping = [
'ac_hide_notice_review' => 'dismiss-review',
'ac-first-login-timestamp' => 'first-login-review',
];
foreach ( $mapping as $old => $new ) {
foreach ( $this->get_users_by_meta_key( $old ) as $user_id ) {
$value = get_user_meta( $user_id, $old, true );
$option = new Preferences\User( 'check-review', $user_id );
$option->set( $new, $value, true );
delete_user_meta( $user_id, $old );
}
}
}
/**
* Update user preferences for addons
*/
private function update_notice_preference_addons() {
$mapping = [
'ac_hide_notice_addons' => 'dismiss-notice',
];
foreach ( $mapping as $old => $new ) {
foreach ( $this->get_users_by_meta_key( $old ) as $user_id ) {
$value = get_user_meta( $user_id, $old, true );
$option = new Preferences\User( 'check-addon-available', $user_id );
$option->set( $new, $value, true );
delete_user_meta( $user_id, $old );
}
}
}
/**
* @param string $key
*
* @return array ID's
*/
protected function get_users_by_meta_key( $key ) {
$user_ids = get_users( [
'fields' => 'ids',
'meta_query' => [
[
'key' => $key,
'compare' => 'EXISTS',
],
],
] );
if ( ! $user_ids ) {
return [];
}
return $user_ids;
}
}