@@ -20,17 +20,17 @@ |
||
| 20 | 20 | defined('WPINC') || die; |
| 21 | 21 | |
| 22 | 22 | if (!class_exists('GL_Plugin_Check_v4')) { |
| 23 | - require_once __DIR__.'/activate.php'; |
|
| 23 | + require_once __DIR__.'/activate.php'; |
|
| 24 | 24 | } |
| 25 | 25 | if ((new GL_Plugin_Check_v4(__FILE__))->canProceed()) { |
| 26 | - require_once __DIR__.'/autoload.php'; |
|
| 27 | - require_once __DIR__.'/compatibility.php'; |
|
| 28 | - require_once __DIR__.'/deprecated.php'; |
|
| 29 | - require_once __DIR__.'/helpers.php'; |
|
| 30 | - $app = new GeminiLabs\SiteReviews\Application(); |
|
| 31 | - $app->make('Provider')->register($app); |
|
| 32 | - register_activation_hook(__FILE__, array($app, 'activate')); |
|
| 33 | - register_deactivation_hook(__FILE__, array($app, 'deactivate')); |
|
| 34 | - register_shutdown_function(array($app, 'catchFatalError')); |
|
| 35 | - $app->init(); |
|
| 26 | + require_once __DIR__.'/autoload.php'; |
|
| 27 | + require_once __DIR__.'/compatibility.php'; |
|
| 28 | + require_once __DIR__.'/deprecated.php'; |
|
| 29 | + require_once __DIR__.'/helpers.php'; |
|
| 30 | + $app = new GeminiLabs\SiteReviews\Application(); |
|
| 31 | + $app->make('Provider')->register($app); |
|
| 32 | + register_activation_hook(__FILE__, array($app, 'activate')); |
|
| 33 | + register_deactivation_hook(__FILE__, array($app, 'deactivate')); |
|
| 34 | + register_shutdown_function(array($app, 'catchFatalError')); |
|
| 35 | + $app->init(); |
|
| 36 | 36 | } |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface PartialContract |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @return string |
|
| 9 | - */ |
|
| 10 | - public function build(array $args = []); |
|
| 7 | + /** |
|
| 8 | + * @return string |
|
| 9 | + */ |
|
| 10 | + public function build(array $args = []); |
|
| 11 | 11 | } |
@@ -7,73 +7,73 @@ |
||
| 7 | 7 | |
| 8 | 8 | class GlobalCountsManager |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @var CountsManager |
|
| 12 | - */ |
|
| 13 | - protected $manager; |
|
| 10 | + /** |
|
| 11 | + * @var CountsManager |
|
| 12 | + */ |
|
| 13 | + protected $manager; |
|
| 14 | 14 | |
| 15 | - public function __construct() |
|
| 16 | - { |
|
| 17 | - $this->manager = glsr(CountsManager::class); |
|
| 18 | - } |
|
| 15 | + public function __construct() |
|
| 16 | + { |
|
| 17 | + $this->manager = glsr(CountsManager::class); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @return array |
|
| 22 | - */ |
|
| 23 | - public function build() |
|
| 24 | - { |
|
| 25 | - return $this->manager->buildCounts(); |
|
| 26 | - } |
|
| 20 | + /** |
|
| 21 | + * @return array |
|
| 22 | + */ |
|
| 23 | + public function build() |
|
| 24 | + { |
|
| 25 | + return $this->manager->buildCounts(); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function decrease(Review $review) |
|
| 32 | - { |
|
| 33 | - $this->update($this->manager->decreaseRating( |
|
| 34 | - $this->get(), |
|
| 35 | - $review->review_type, |
|
| 36 | - $review->rating |
|
| 37 | - )); |
|
| 38 | - } |
|
| 28 | + /** |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function decrease(Review $review) |
|
| 32 | + { |
|
| 33 | + $this->update($this->manager->decreaseRating( |
|
| 34 | + $this->get(), |
|
| 35 | + $review->review_type, |
|
| 36 | + $review->rating |
|
| 37 | + )); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @return array |
|
| 42 | - */ |
|
| 43 | - public function get() |
|
| 44 | - { |
|
| 45 | - $counts = glsr(OptionManager::class)->get('counts', []); |
|
| 46 | - if (!is_array($counts)) { |
|
| 47 | - glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
| 48 | - return []; |
|
| 49 | - } |
|
| 50 | - return $counts; |
|
| 51 | - } |
|
| 40 | + /** |
|
| 41 | + * @return array |
|
| 42 | + */ |
|
| 43 | + public function get() |
|
| 44 | + { |
|
| 45 | + $counts = glsr(OptionManager::class)->get('counts', []); |
|
| 46 | + if (!is_array($counts)) { |
|
| 47 | + glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
| 48 | + return []; |
|
| 49 | + } |
|
| 50 | + return $counts; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return void |
|
| 55 | - */ |
|
| 56 | - public function increase(Review $review) |
|
| 57 | - { |
|
| 58 | - if (empty($counts = $this->get())) { |
|
| 59 | - $counts = $this->build(); |
|
| 60 | - } |
|
| 61 | - $this->update($this->manager->increaseRating($counts, $review->review_type, $review->rating)); |
|
| 62 | - } |
|
| 53 | + /** |
|
| 54 | + * @return void |
|
| 55 | + */ |
|
| 56 | + public function increase(Review $review) |
|
| 57 | + { |
|
| 58 | + if (empty($counts = $this->get())) { |
|
| 59 | + $counts = $this->build(); |
|
| 60 | + } |
|
| 61 | + $this->update($this->manager->increaseRating($counts, $review->review_type, $review->rating)); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @return void |
|
| 66 | - */ |
|
| 67 | - public function update(array $reviewCounts) |
|
| 68 | - { |
|
| 69 | - glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
| 70 | - } |
|
| 64 | + /** |
|
| 65 | + * @return void |
|
| 66 | + */ |
|
| 67 | + public function update(array $reviewCounts) |
|
| 68 | + { |
|
| 69 | + glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @return void |
|
| 74 | - */ |
|
| 75 | - public function updateAll() |
|
| 76 | - { |
|
| 77 | - $this->update($this->build()); |
|
| 78 | - } |
|
| 72 | + /** |
|
| 73 | + * @return void |
|
| 74 | + */ |
|
| 75 | + public function updateAll() |
|
| 76 | + { |
|
| 77 | + $this->update($this->build()); |
|
| 78 | + } |
|
| 79 | 79 | } |
@@ -7,87 +7,87 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Date |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * [60, 1], |
|
| 12 | - * [60 * 100, 60], |
|
| 13 | - * [3600 * 70, 3600], |
|
| 14 | - * [3600 * 24 * 10, 3600 * 24], |
|
| 15 | - * [3600 * 24 * 30, 3600 * 24 * 7], |
|
| 16 | - * [3600 * 24 * 30 * 30, 3600 * 24 * 30], |
|
| 17 | - * [INF, 3600 * 24 * 265],. |
|
| 18 | - */ |
|
| 19 | - protected static $TIME_PERIODS = [ |
|
| 20 | - [60, 1], |
|
| 21 | - [6000, 60], |
|
| 22 | - [252000, 3600], |
|
| 23 | - [864000, 86400], |
|
| 24 | - [2592000, 604800], |
|
| 25 | - [77760000, 2592000], |
|
| 26 | - [INF, 22896000], |
|
| 27 | - ]; |
|
| 10 | + /** |
|
| 11 | + * [60, 1], |
|
| 12 | + * [60 * 100, 60], |
|
| 13 | + * [3600 * 70, 3600], |
|
| 14 | + * [3600 * 24 * 10, 3600 * 24], |
|
| 15 | + * [3600 * 24 * 30, 3600 * 24 * 7], |
|
| 16 | + * [3600 * 24 * 30 * 30, 3600 * 24 * 30], |
|
| 17 | + * [INF, 3600 * 24 * 265],. |
|
| 18 | + */ |
|
| 19 | + protected static $TIME_PERIODS = [ |
|
| 20 | + [60, 1], |
|
| 21 | + [6000, 60], |
|
| 22 | + [252000, 3600], |
|
| 23 | + [864000, 86400], |
|
| 24 | + [2592000, 604800], |
|
| 25 | + [77760000, 2592000], |
|
| 26 | + [INF, 22896000], |
|
| 27 | + ]; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @param mixed $date |
|
| 31 | - * @param string $format |
|
| 32 | - * @return bool |
|
| 33 | - */ |
|
| 34 | - public function isDate($date, $format = 'Y-m-d H:i:s') |
|
| 35 | - { |
|
| 36 | - $datetime = DateTime::createFromFormat($format, $date); |
|
| 37 | - return $datetime && $date == $datetime->format($format); |
|
| 38 | - } |
|
| 29 | + /** |
|
| 30 | + * @param mixed $date |
|
| 31 | + * @param string $format |
|
| 32 | + * @return bool |
|
| 33 | + */ |
|
| 34 | + public function isDate($date, $format = 'Y-m-d H:i:s') |
|
| 35 | + { |
|
| 36 | + $datetime = DateTime::createFromFormat($format, $date); |
|
| 37 | + return $datetime && $date == $datetime->format($format); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param mixed $date |
|
| 42 | - * @return bool |
|
| 43 | - */ |
|
| 44 | - public function isTimestamp($date) |
|
| 45 | - { |
|
| 46 | - return ctype_digit($date) |
|
| 47 | - ? true |
|
| 48 | - : false; |
|
| 49 | - } |
|
| 40 | + /** |
|
| 41 | + * @param mixed $date |
|
| 42 | + * @return bool |
|
| 43 | + */ |
|
| 44 | + public function isTimestamp($date) |
|
| 45 | + { |
|
| 46 | + return ctype_digit($date) |
|
| 47 | + ? true |
|
| 48 | + : false; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param mixed $date |
|
| 53 | - * @param string $fallback |
|
| 54 | - * @return string |
|
| 55 | - */ |
|
| 56 | - public function localized($date, $fallback = '') |
|
| 57 | - { |
|
| 58 | - return $this->isDate($date) || $this->isTimestamp($date) |
|
| 59 | - ? date_i18n('Y-m-d H:i', $date) |
|
| 60 | - : $fallback; |
|
| 61 | - } |
|
| 51 | + /** |
|
| 52 | + * @param mixed $date |
|
| 53 | + * @param string $fallback |
|
| 54 | + * @return string |
|
| 55 | + */ |
|
| 56 | + public function localized($date, $fallback = '') |
|
| 57 | + { |
|
| 58 | + return $this->isDate($date) || $this->isTimestamp($date) |
|
| 59 | + ? date_i18n('Y-m-d H:i', $date) |
|
| 60 | + : $fallback; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @param mixed $date |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public function relative($date) |
|
| 68 | - { |
|
| 69 | - if (!$this->isDate($date)) { |
|
| 70 | - return ''; |
|
| 71 | - } |
|
| 72 | - $diff = time() - strtotime($date); |
|
| 73 | - foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
| 74 | - if ($diff > $timePeriod[0]) { |
|
| 75 | - continue; |
|
| 76 | - } |
|
| 77 | - $unit = intval(floor($diff / $timePeriod[1])); |
|
| 78 | - $relativeDates = [ |
|
| 79 | - _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
| 80 | - _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
| 81 | - _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
| 82 | - _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
| 83 | - _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
| 84 | - _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
| 85 | - _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
| 86 | - ]; |
|
| 87 | - $relativeDate = $relativeDates[$i]; |
|
| 88 | - return Str::contains($relativeDate, '%s') |
|
| 89 | - ? sprintf($relativeDate, $unit) |
|
| 90 | - : $relativeDate; |
|
| 91 | - } |
|
| 92 | - } |
|
| 63 | + /** |
|
| 64 | + * @param mixed $date |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public function relative($date) |
|
| 68 | + { |
|
| 69 | + if (!$this->isDate($date)) { |
|
| 70 | + return ''; |
|
| 71 | + } |
|
| 72 | + $diff = time() - strtotime($date); |
|
| 73 | + foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
| 74 | + if ($diff > $timePeriod[0]) { |
|
| 75 | + continue; |
|
| 76 | + } |
|
| 77 | + $unit = intval(floor($diff / $timePeriod[1])); |
|
| 78 | + $relativeDates = [ |
|
| 79 | + _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
| 80 | + _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
| 81 | + _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
| 82 | + _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
| 83 | + _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
| 84 | + _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
| 85 | + _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
| 86 | + ]; |
|
| 87 | + $relativeDate = $relativeDates[$i]; |
|
| 88 | + return Str::contains($relativeDate, '%s') |
|
| 89 | + ? sprintf($relativeDate, $unit) |
|
| 90 | + : $relativeDate; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -9,70 +9,70 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Migrate_4_0_2 |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @return void |
|
| 14 | - */ |
|
| 15 | - public function deleteSessions() |
|
| 16 | - { |
|
| 17 | - global $wpdb; |
|
| 18 | - $wpdb->query(" |
|
| 12 | + /** |
|
| 13 | + * @return void |
|
| 14 | + */ |
|
| 15 | + public function deleteSessions() |
|
| 16 | + { |
|
| 17 | + global $wpdb; |
|
| 18 | + $wpdb->query(" |
|
| 19 | 19 | DELETE |
| 20 | 20 | FROM {$wpdb->options} |
| 21 | 21 | WHERE option_name LIKE '_glsr_session%' |
| 22 | 22 | "); |
| 23 | - } |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return void |
|
| 27 | - */ |
|
| 28 | - public function migrateSettings() |
|
| 29 | - { |
|
| 30 | - if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
| 31 | - $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang') |
|
| 32 | - ? 'polylang' |
|
| 33 | - : ''; |
|
| 34 | - $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual); |
|
| 35 | - $settings = Arr::set($settings, 'settings.general.rebusify', 'no'); |
|
| 36 | - $settings = Arr::set($settings, 'settings.general.rebusify_email', ''); |
|
| 37 | - $settings = Arr::set($settings, 'settings.general.rebusify_serial', ''); |
|
| 38 | - $settings = Arr::set($settings, 'settings.reviews.name.format', ''); |
|
| 39 | - $settings = Arr::set($settings, 'settings.reviews.name.initial', ''); |
|
| 40 | - $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', ''); |
|
| 41 | - $settings = Arr::set($settings, 'settings.submissions.limit', ''); |
|
| 42 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
| 43 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
| 44 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
| 45 | - unset($settings['settings']['general']['support']); |
|
| 46 | - update_option(OptionManager::databaseKey(4), $settings); |
|
| 47 | - } |
|
| 48 | - } |
|
| 25 | + /** |
|
| 26 | + * @return void |
|
| 27 | + */ |
|
| 28 | + public function migrateSettings() |
|
| 29 | + { |
|
| 30 | + if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
| 31 | + $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang') |
|
| 32 | + ? 'polylang' |
|
| 33 | + : ''; |
|
| 34 | + $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual); |
|
| 35 | + $settings = Arr::set($settings, 'settings.general.rebusify', 'no'); |
|
| 36 | + $settings = Arr::set($settings, 'settings.general.rebusify_email', ''); |
|
| 37 | + $settings = Arr::set($settings, 'settings.general.rebusify_serial', ''); |
|
| 38 | + $settings = Arr::set($settings, 'settings.reviews.name.format', ''); |
|
| 39 | + $settings = Arr::set($settings, 'settings.reviews.name.initial', ''); |
|
| 40 | + $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', ''); |
|
| 41 | + $settings = Arr::set($settings, 'settings.submissions.limit', ''); |
|
| 42 | + $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
| 43 | + $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
| 44 | + $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
| 45 | + unset($settings['settings']['general']['support']); |
|
| 46 | + update_option(OptionManager::databaseKey(4), $settings); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @return void |
|
| 52 | - */ |
|
| 53 | - public function protectMetaKeys() |
|
| 54 | - { |
|
| 55 | - global $wpdb; |
|
| 56 | - $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
| 57 | - $keys = implode("','", $keys); |
|
| 58 | - $postType = Application::POST_TYPE; |
|
| 59 | - $wpdb->query(" |
|
| 50 | + /** |
|
| 51 | + * @return void |
|
| 52 | + */ |
|
| 53 | + public function protectMetaKeys() |
|
| 54 | + { |
|
| 55 | + global $wpdb; |
|
| 56 | + $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
| 57 | + $keys = implode("','", $keys); |
|
| 58 | + $postType = Application::POST_TYPE; |
|
| 59 | + $wpdb->query(" |
|
| 60 | 60 | UPDATE {$wpdb->postmeta} pm |
| 61 | 61 | INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id |
| 62 | 62 | SET pm.meta_key = CONCAT('_', pm.meta_key) |
| 63 | 63 | WHERE pm.meta_key IN ('{$keys}') |
| 64 | 64 | AND p.post_type = '{$postType}' |
| 65 | 65 | "); |
| 66 | - } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - public function run() |
|
| 72 | - { |
|
| 73 | - $this->migrateSettings(); |
|
| 74 | - $this->protectMetaKeys(); |
|
| 75 | - $this->deleteSessions(); |
|
| 76 | - delete_transient(Application::ID.'_cloudflare_ips'); |
|
| 77 | - } |
|
| 68 | + /** |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + public function run() |
|
| 72 | + { |
|
| 73 | + $this->migrateSettings(); |
|
| 74 | + $this->protectMetaKeys(); |
|
| 75 | + $this->deleteSessions(); |
|
| 76 | + delete_transient(Application::ID.'_cloudflare_ips'); |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -14,248 +14,248 @@ |
||
| 14 | 14 | |
| 15 | 15 | class CountsManager |
| 16 | 16 | { |
| 17 | - const LIMIT = 500; |
|
| 18 | - const META_AVERAGE = '_glsr_average'; |
|
| 19 | - const META_COUNT = '_glsr_count'; |
|
| 20 | - const META_RANKING = '_glsr_ranking'; |
|
| 17 | + const LIMIT = 500; |
|
| 18 | + const META_AVERAGE = '_glsr_average'; |
|
| 19 | + const META_COUNT = '_glsr_count'; |
|
| 20 | + const META_RANKING = '_glsr_ranking'; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @return array |
|
| 24 | - */ |
|
| 25 | - public function buildCounts(array $args = []) |
|
| 26 | - { |
|
| 27 | - $counts = [ |
|
| 28 | - 'local' => $this->generateEmptyCountsArray(), |
|
| 29 | - ]; |
|
| 30 | - $query = $this->queryReviews($args); |
|
| 31 | - while ($query) { |
|
| 32 | - $counts = $this->populateCountsFromQuery($query, $counts); |
|
| 33 | - $query = $query->has_more |
|
| 34 | - ? $this->queryReviews($args, end($query->reviews)->ID) |
|
| 35 | - : false; |
|
| 36 | - } |
|
| 37 | - return $counts; |
|
| 38 | - } |
|
| 22 | + /** |
|
| 23 | + * @return array |
|
| 24 | + */ |
|
| 25 | + public function buildCounts(array $args = []) |
|
| 26 | + { |
|
| 27 | + $counts = [ |
|
| 28 | + 'local' => $this->generateEmptyCountsArray(), |
|
| 29 | + ]; |
|
| 30 | + $query = $this->queryReviews($args); |
|
| 31 | + while ($query) { |
|
| 32 | + $counts = $this->populateCountsFromQuery($query, $counts); |
|
| 33 | + $query = $query->has_more |
|
| 34 | + ? $this->queryReviews($args, end($query->reviews)->ID) |
|
| 35 | + : false; |
|
| 36 | + } |
|
| 37 | + return $counts; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @return void |
|
| 42 | - */ |
|
| 43 | - public function decreaseAll(Review $review) |
|
| 44 | - { |
|
| 45 | - glsr(GlobalCountsManager::class)->decrease($review); |
|
| 46 | - glsr(PostCountsManager::class)->decrease($review); |
|
| 47 | - glsr(TermCountsManager::class)->decrease($review); |
|
| 48 | - } |
|
| 40 | + /** |
|
| 41 | + * @return void |
|
| 42 | + */ |
|
| 43 | + public function decreaseAll(Review $review) |
|
| 44 | + { |
|
| 45 | + glsr(GlobalCountsManager::class)->decrease($review); |
|
| 46 | + glsr(PostCountsManager::class)->decrease($review); |
|
| 47 | + glsr(TermCountsManager::class)->decrease($review); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param string $type |
|
| 52 | - * @param int $rating |
|
| 53 | - * @return array |
|
| 54 | - */ |
|
| 55 | - public function decreaseRating(array $reviewCounts, $type, $rating) |
|
| 56 | - { |
|
| 57 | - if (isset($reviewCounts[$type][$rating])) { |
|
| 58 | - $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
| 59 | - } |
|
| 60 | - return $reviewCounts; |
|
| 61 | - } |
|
| 50 | + /** |
|
| 51 | + * @param string $type |
|
| 52 | + * @param int $rating |
|
| 53 | + * @return array |
|
| 54 | + */ |
|
| 55 | + public function decreaseRating(array $reviewCounts, $type, $rating) |
|
| 56 | + { |
|
| 57 | + if (isset($reviewCounts[$type][$rating])) { |
|
| 58 | + $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
| 59 | + } |
|
| 60 | + return $reviewCounts; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @return array |
|
| 65 | - */ |
|
| 66 | - public function flatten(array $reviewCounts, array $args = []) |
|
| 67 | - { |
|
| 68 | - $counts = []; |
|
| 69 | - array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
| 70 | - $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
| 71 | - }); |
|
| 72 | - $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class)); |
|
| 73 | - $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class)); |
|
| 74 | - foreach ($counts as $index => &$num) { |
|
| 75 | - if (!Helper::inRange($index, $min, $max)) { |
|
| 76 | - $num = 0; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - return $counts; |
|
| 80 | - } |
|
| 63 | + /** |
|
| 64 | + * @return array |
|
| 65 | + */ |
|
| 66 | + public function flatten(array $reviewCounts, array $args = []) |
|
| 67 | + { |
|
| 68 | + $counts = []; |
|
| 69 | + array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
| 70 | + $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
| 71 | + }); |
|
| 72 | + $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class)); |
|
| 73 | + $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class)); |
|
| 74 | + foreach ($counts as $index => &$num) { |
|
| 75 | + if (!Helper::inRange($index, $min, $max)) { |
|
| 76 | + $num = 0; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + return $counts; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @return array |
|
| 84 | - */ |
|
| 85 | - public function getCounts(array $args = []) |
|
| 86 | - { |
|
| 87 | - $args = $this->normalizeArgs($args); |
|
| 88 | - $counts = $this->hasMixedAssignment($args) |
|
| 89 | - ? $this->buildCounts($args) // force query the database |
|
| 90 | - : $this->get($args); |
|
| 91 | - return $this->normalize($counts); |
|
| 92 | - } |
|
| 82 | + /** |
|
| 83 | + * @return array |
|
| 84 | + */ |
|
| 85 | + public function getCounts(array $args = []) |
|
| 86 | + { |
|
| 87 | + $args = $this->normalizeArgs($args); |
|
| 88 | + $counts = $this->hasMixedAssignment($args) |
|
| 89 | + ? $this->buildCounts($args) // force query the database |
|
| 90 | + : $this->get($args); |
|
| 91 | + return $this->normalize($counts); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @return void |
|
| 96 | - */ |
|
| 97 | - public function increaseAll(Review $review) |
|
| 98 | - { |
|
| 99 | - glsr(GlobalCountsManager::class)->increase($review); |
|
| 100 | - glsr(PostCountsManager::class)->increase($review); |
|
| 101 | - glsr(TermCountsManager::class)->increase($review); |
|
| 102 | - } |
|
| 94 | + /** |
|
| 95 | + * @return void |
|
| 96 | + */ |
|
| 97 | + public function increaseAll(Review $review) |
|
| 98 | + { |
|
| 99 | + glsr(GlobalCountsManager::class)->increase($review); |
|
| 100 | + glsr(PostCountsManager::class)->increase($review); |
|
| 101 | + glsr(TermCountsManager::class)->increase($review); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * @param string $type |
|
| 106 | - * @param int $rating |
|
| 107 | - * @return array |
|
| 108 | - */ |
|
| 109 | - public function increaseRating(array $reviewCounts, $type, $rating) |
|
| 110 | - { |
|
| 111 | - if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
| 112 | - return $reviewCounts; |
|
| 113 | - } |
|
| 114 | - if (!array_key_exists($type, $reviewCounts)) { |
|
| 115 | - $reviewCounts[$type] = []; |
|
| 116 | - } |
|
| 117 | - $reviewCounts = $this->normalize($reviewCounts); |
|
| 118 | - $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
| 119 | - return $reviewCounts; |
|
| 120 | - } |
|
| 104 | + /** |
|
| 105 | + * @param string $type |
|
| 106 | + * @param int $rating |
|
| 107 | + * @return array |
|
| 108 | + */ |
|
| 109 | + public function increaseRating(array $reviewCounts, $type, $rating) |
|
| 110 | + { |
|
| 111 | + if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
| 112 | + return $reviewCounts; |
|
| 113 | + } |
|
| 114 | + if (!array_key_exists($type, $reviewCounts)) { |
|
| 115 | + $reviewCounts[$type] = []; |
|
| 116 | + } |
|
| 117 | + $reviewCounts = $this->normalize($reviewCounts); |
|
| 118 | + $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
| 119 | + return $reviewCounts; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * @return void |
|
| 124 | - */ |
|
| 125 | - public function updateAll() |
|
| 126 | - { |
|
| 127 | - glsr(GlobalCountsManager::class)->updateAll(); |
|
| 128 | - glsr(PostCountsManager::class)->updateAll(); |
|
| 129 | - glsr(TermCountsManager::class)->updateAll(); |
|
| 130 | - glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
| 131 | - } |
|
| 122 | + /** |
|
| 123 | + * @return void |
|
| 124 | + */ |
|
| 125 | + public function updateAll() |
|
| 126 | + { |
|
| 127 | + glsr(GlobalCountsManager::class)->updateAll(); |
|
| 128 | + glsr(PostCountsManager::class)->updateAll(); |
|
| 129 | + glsr(TermCountsManager::class)->updateAll(); |
|
| 130 | + glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * @return array |
|
| 135 | - */ |
|
| 136 | - protected function combine(array $results) |
|
| 137 | - { |
|
| 138 | - if (!wp_is_numeric_array($results)) { |
|
| 139 | - return $results; |
|
| 140 | - } |
|
| 141 | - $mergedKeys = array_keys(array_merge(...$results)); |
|
| 142 | - $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray()); |
|
| 143 | - foreach ($results as $typeRatings) { |
|
| 144 | - foreach ($typeRatings as $type => $ratings) { |
|
| 145 | - foreach ($ratings as $index => $rating) { |
|
| 146 | - $counts[$type][$index] = intval($rating) + $counts[$type][$index]; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - return $counts; |
|
| 151 | - } |
|
| 133 | + /** |
|
| 134 | + * @return array |
|
| 135 | + */ |
|
| 136 | + protected function combine(array $results) |
|
| 137 | + { |
|
| 138 | + if (!wp_is_numeric_array($results)) { |
|
| 139 | + return $results; |
|
| 140 | + } |
|
| 141 | + $mergedKeys = array_keys(array_merge(...$results)); |
|
| 142 | + $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray()); |
|
| 143 | + foreach ($results as $typeRatings) { |
|
| 144 | + foreach ($typeRatings as $type => $ratings) { |
|
| 145 | + foreach ($ratings as $index => $rating) { |
|
| 146 | + $counts[$type][$index] = intval($rating) + $counts[$type][$index]; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + return $counts; |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * @return array |
|
| 155 | - */ |
|
| 156 | - protected function generateEmptyCountsArray() |
|
| 157 | - { |
|
| 158 | - return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
| 159 | - } |
|
| 153 | + /** |
|
| 154 | + * @return array |
|
| 155 | + */ |
|
| 156 | + protected function generateEmptyCountsArray() |
|
| 157 | + { |
|
| 158 | + return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * @return array |
|
| 163 | - */ |
|
| 164 | - protected function get($args) |
|
| 165 | - { |
|
| 166 | - $results = []; |
|
| 167 | - foreach ($args['post_ids'] as $postId) { |
|
| 168 | - $results[] = glsr(PostCountsManager::class)->get($postId); |
|
| 169 | - } |
|
| 170 | - foreach ($args['term_ids'] as $termId) { |
|
| 171 | - $results[] = glsr(TermCountsManager::class)->get($termId); |
|
| 172 | - } |
|
| 173 | - if (empty($results)) { |
|
| 174 | - $results[] = glsr(GlobalCountsManager::class)->get(); |
|
| 175 | - } |
|
| 176 | - $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback |
|
| 177 | - return $this->combine($results); |
|
| 178 | - } |
|
| 161 | + /** |
|
| 162 | + * @return array |
|
| 163 | + */ |
|
| 164 | + protected function get($args) |
|
| 165 | + { |
|
| 166 | + $results = []; |
|
| 167 | + foreach ($args['post_ids'] as $postId) { |
|
| 168 | + $results[] = glsr(PostCountsManager::class)->get($postId); |
|
| 169 | + } |
|
| 170 | + foreach ($args['term_ids'] as $termId) { |
|
| 171 | + $results[] = glsr(TermCountsManager::class)->get($termId); |
|
| 172 | + } |
|
| 173 | + if (empty($results)) { |
|
| 174 | + $results[] = glsr(GlobalCountsManager::class)->get(); |
|
| 175 | + } |
|
| 176 | + $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback |
|
| 177 | + return $this->combine($results); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * @return bool |
|
| 182 | - */ |
|
| 183 | - protected function hasMixedAssignment(array $args) |
|
| 184 | - { |
|
| 185 | - return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
| 186 | - } |
|
| 180 | + /** |
|
| 181 | + * @return bool |
|
| 182 | + */ |
|
| 183 | + protected function hasMixedAssignment(array $args) |
|
| 184 | + { |
|
| 185 | + return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * @return array |
|
| 190 | - */ |
|
| 191 | - protected function normalize(array $reviewCounts) |
|
| 192 | - { |
|
| 193 | - foreach ($reviewCounts as &$counts) { |
|
| 194 | - foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
| 195 | - if (!isset($counts[$index])) { |
|
| 196 | - $counts[$index] = 0; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - ksort($counts); |
|
| 200 | - } |
|
| 201 | - return $reviewCounts; |
|
| 202 | - } |
|
| 188 | + /** |
|
| 189 | + * @return array |
|
| 190 | + */ |
|
| 191 | + protected function normalize(array $reviewCounts) |
|
| 192 | + { |
|
| 193 | + foreach ($reviewCounts as &$counts) { |
|
| 194 | + foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
| 195 | + if (!isset($counts[$index])) { |
|
| 196 | + $counts[$index] = 0; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + ksort($counts); |
|
| 200 | + } |
|
| 201 | + return $reviewCounts; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * @return array |
|
| 206 | - */ |
|
| 207 | - protected function normalizeArgs(array $args) |
|
| 208 | - { |
|
| 209 | - $args = wp_parse_args(array_filter($args), [ |
|
| 210 | - 'post_ids' => [], |
|
| 211 | - 'term_ids' => [], |
|
| 212 | - 'type' => 'local', |
|
| 213 | - ]); |
|
| 214 | - $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
| 215 | - $args['type'] = $this->normalizeType($args['type']); |
|
| 216 | - return $args; |
|
| 217 | - } |
|
| 204 | + /** |
|
| 205 | + * @return array |
|
| 206 | + */ |
|
| 207 | + protected function normalizeArgs(array $args) |
|
| 208 | + { |
|
| 209 | + $args = wp_parse_args(array_filter($args), [ |
|
| 210 | + 'post_ids' => [], |
|
| 211 | + 'term_ids' => [], |
|
| 212 | + 'type' => 'local', |
|
| 213 | + ]); |
|
| 214 | + $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
| 215 | + $args['type'] = $this->normalizeType($args['type']); |
|
| 216 | + return $args; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - /** |
|
| 220 | - * @param string $type |
|
| 221 | - * @return string |
|
| 222 | - */ |
|
| 223 | - protected function normalizeType($type) |
|
| 224 | - { |
|
| 225 | - return empty($type) || !is_string($type) |
|
| 226 | - ? 'local' |
|
| 227 | - : $type; |
|
| 228 | - } |
|
| 219 | + /** |
|
| 220 | + * @param string $type |
|
| 221 | + * @return string |
|
| 222 | + */ |
|
| 223 | + protected function normalizeType($type) |
|
| 224 | + { |
|
| 225 | + return empty($type) || !is_string($type) |
|
| 226 | + ? 'local' |
|
| 227 | + : $type; |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - /** |
|
| 231 | - * @param object $query |
|
| 232 | - * @return array |
|
| 233 | - */ |
|
| 234 | - protected function populateCountsFromQuery($query, array $counts) |
|
| 235 | - { |
|
| 236 | - foreach ($query->reviews as $review) { |
|
| 237 | - $type = $this->normalizeType($review->type); |
|
| 238 | - if (!array_key_exists($type, $counts)) { |
|
| 239 | - $counts[$type] = $this->generateEmptyCountsArray(); |
|
| 240 | - } |
|
| 241 | - ++$counts[$type][$review->rating]; |
|
| 242 | - } |
|
| 243 | - return $counts; |
|
| 244 | - } |
|
| 230 | + /** |
|
| 231 | + * @param object $query |
|
| 232 | + * @return array |
|
| 233 | + */ |
|
| 234 | + protected function populateCountsFromQuery($query, array $counts) |
|
| 235 | + { |
|
| 236 | + foreach ($query->reviews as $review) { |
|
| 237 | + $type = $this->normalizeType($review->type); |
|
| 238 | + if (!array_key_exists($type, $counts)) { |
|
| 239 | + $counts[$type] = $this->generateEmptyCountsArray(); |
|
| 240 | + } |
|
| 241 | + ++$counts[$type][$review->rating]; |
|
| 242 | + } |
|
| 243 | + return $counts; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - /** |
|
| 247 | - * @param int $lastPostId |
|
| 248 | - * @return object |
|
| 249 | - */ |
|
| 250 | - protected function queryReviews(array $args = [], $lastPostId = 0) |
|
| 251 | - { |
|
| 252 | - $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
| 253 | - $hasMore = is_array($reviews) |
|
| 254 | - ? count($reviews) == static::LIMIT |
|
| 255 | - : false; |
|
| 256 | - return (object) [ |
|
| 257 | - 'has_more' => $hasMore, |
|
| 258 | - 'reviews' => $reviews, |
|
| 259 | - ]; |
|
| 260 | - } |
|
| 246 | + /** |
|
| 247 | + * @param int $lastPostId |
|
| 248 | + * @return object |
|
| 249 | + */ |
|
| 250 | + protected function queryReviews(array $args = [], $lastPostId = 0) |
|
| 251 | + { |
|
| 252 | + $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
| 253 | + $hasMore = is_array($reviews) |
|
| 254 | + ? count($reviews) == static::LIMIT |
|
| 255 | + : false; |
|
| 256 | + return (object) [ |
|
| 257 | + 'has_more' => $hasMore, |
|
| 258 | + 'reviews' => $reviews, |
|
| 259 | + ]; |
|
| 260 | + } |
|
| 261 | 261 | } |
@@ -6,11 +6,11 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Migrate_4_4_0 |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @return void |
|
| 11 | - */ |
|
| 12 | - public function run() |
|
| 13 | - { |
|
| 14 | - glsr(Role::class)->resetAll(); |
|
| 15 | - } |
|
| 9 | + /** |
|
| 10 | + * @return void |
|
| 11 | + */ |
|
| 12 | + public function run() |
|
| 13 | + { |
|
| 14 | + glsr(Role::class)->resetAll(); |
|
| 15 | + } |
|
| 16 | 16 | } |
@@ -8,66 +8,66 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Migrate_4_5_0 |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function migrateOptions() |
|
| 15 | - { |
|
| 16 | - $isAccountVerified = glsr(OptionManager::class)->getWP('_glsr_rebusify', false); |
|
| 17 | - update_option('_glsr_trustalyze', $isAccountVerified); |
|
| 18 | - delete_option('_glsr_rebusify'); |
|
| 19 | - } |
|
| 11 | + /** |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function migrateOptions() |
|
| 15 | + { |
|
| 16 | + $isAccountVerified = glsr(OptionManager::class)->getWP('_glsr_rebusify', false); |
|
| 17 | + update_option('_glsr_trustalyze', $isAccountVerified); |
|
| 18 | + delete_option('_glsr_rebusify'); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @return void |
|
| 23 | - */ |
|
| 24 | - public function migrateSettings() |
|
| 25 | - { |
|
| 26 | - if ($settings = get_option(OptionManager::databaseKey(4))) { |
|
| 27 | - $settings = Arr::set($settings, 'settings.general.trustalyze', |
|
| 28 | - Arr::get($settings, 'settings.general.rebusify') |
|
| 29 | - ); |
|
| 30 | - $settings = Arr::set($settings, 'settings.general.trustalyze_email', |
|
| 31 | - Arr::get($settings, 'settings.general.rebusify_email') |
|
| 32 | - ); |
|
| 33 | - $settings = Arr::set($settings, 'settings.general.trustalyze_serial', |
|
| 34 | - Arr::get($settings, 'settings.general.rebusify_serial') |
|
| 35 | - ); |
|
| 36 | - unset($settings['settings']['general']['rebusify']); |
|
| 37 | - unset($settings['settings']['general']['rebusify_email']); |
|
| 38 | - unset($settings['settings']['general']['rebusify_serial']); |
|
| 39 | - update_option(OptionManager::databaseKey(4), $settings); |
|
| 40 | - } |
|
| 41 | - } |
|
| 21 | + /** |
|
| 22 | + * @return void |
|
| 23 | + */ |
|
| 24 | + public function migrateSettings() |
|
| 25 | + { |
|
| 26 | + if ($settings = get_option(OptionManager::databaseKey(4))) { |
|
| 27 | + $settings = Arr::set($settings, 'settings.general.trustalyze', |
|
| 28 | + Arr::get($settings, 'settings.general.rebusify') |
|
| 29 | + ); |
|
| 30 | + $settings = Arr::set($settings, 'settings.general.trustalyze_email', |
|
| 31 | + Arr::get($settings, 'settings.general.rebusify_email') |
|
| 32 | + ); |
|
| 33 | + $settings = Arr::set($settings, 'settings.general.trustalyze_serial', |
|
| 34 | + Arr::get($settings, 'settings.general.rebusify_serial') |
|
| 35 | + ); |
|
| 36 | + unset($settings['settings']['general']['rebusify']); |
|
| 37 | + unset($settings['settings']['general']['rebusify_email']); |
|
| 38 | + unset($settings['settings']['general']['rebusify_serial']); |
|
| 39 | + update_option(OptionManager::databaseKey(4), $settings); |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - public function migrateUserMeta() |
|
| 47 | - { |
|
| 48 | - $metaKey = NoticeController::USER_META_KEY; |
|
| 49 | - $userIds = get_users([ |
|
| 50 | - 'fields' => 'ID', |
|
| 51 | - 'meta_compare' => 'EXISTS', |
|
| 52 | - 'meta_key' => $metaKey, |
|
| 53 | - ]); |
|
| 54 | - foreach ($userIds as $userId) { |
|
| 55 | - $meta = (array) get_user_meta($userId, $metaKey, true); |
|
| 56 | - if (array_key_exists('rebusify', $meta)) { |
|
| 57 | - $meta['trustalyze'] = $meta['rebusify']; |
|
| 58 | - unset($meta['rebusify']); |
|
| 59 | - update_user_meta($userId, $metaKey, $meta); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 43 | + /** |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + public function migrateUserMeta() |
|
| 47 | + { |
|
| 48 | + $metaKey = NoticeController::USER_META_KEY; |
|
| 49 | + $userIds = get_users([ |
|
| 50 | + 'fields' => 'ID', |
|
| 51 | + 'meta_compare' => 'EXISTS', |
|
| 52 | + 'meta_key' => $metaKey, |
|
| 53 | + ]); |
|
| 54 | + foreach ($userIds as $userId) { |
|
| 55 | + $meta = (array) get_user_meta($userId, $metaKey, true); |
|
| 56 | + if (array_key_exists('rebusify', $meta)) { |
|
| 57 | + $meta['trustalyze'] = $meta['rebusify']; |
|
| 58 | + unset($meta['rebusify']); |
|
| 59 | + update_user_meta($userId, $metaKey, $meta); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @return void |
|
| 66 | - */ |
|
| 67 | - public function run() |
|
| 68 | - { |
|
| 69 | - $this->migrateOptions(); |
|
| 70 | - $this->migrateSettings(); |
|
| 71 | - $this->migrateUserMeta(); |
|
| 72 | - } |
|
| 64 | + /** |
|
| 65 | + * @return void |
|
| 66 | + */ |
|
| 67 | + public function run() |
|
| 68 | + { |
|
| 69 | + $this->migrateOptions(); |
|
| 70 | + $this->migrateSettings(); |
|
| 71 | + $this->migrateUserMeta(); |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -11,6 +11,6 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Upgrader |
| 13 | 13 | { |
| 14 | - public function run() |
|
| 15 | - {} |
|
| 14 | + public function run() |
|
| 15 | + {} |
|
| 16 | 16 | } |