| 1 |
<?php #comp-page builds: premium |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Adds new columns |
| 10 |
*/ |
| 11 |
class WINPUpdate020302 extends Wbcr_Factory450_Update { |
| 12 |
|
| 13 |
public function install() { |
| 14 |
if ( is_multisite() && $this->plugin->isNetworkActive() ) { |
| 15 |
global $wpdb; |
| 16 |
|
| 17 |
$blogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
| 18 |
|
| 19 |
if ( ! empty( $blogs ) ) { |
| 20 |
foreach ( $blogs as $id ) { |
| 21 |
|
| 22 |
switch_to_blog( $id ); |
| 23 |
|
| 24 |
$this->new_migration(); |
| 25 |
|
| 26 |
restore_current_blog(); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
WINP_Helper::flush_page_cache(); |
| 31 |
|
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
$this->new_migration(); |
| 36 |
WINP_Helper::flush_page_cache(); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* @author Artem Prihodko <webtemyk@yandex.ru> |
| 41 |
* @since 2.3.2 |
| 42 |
*/ |
| 43 |
public function new_migration() { |
| 44 |
wp_raise_memory_limit(); |
| 45 |
|
| 46 |
global $wpdb; |
| 47 |
|
| 48 |
$snippets = $wpdb->get_results( " |
| 49 |
SELECT p.ID |
| 50 |
FROM {$wpdb->posts} p |
| 51 |
INNER JOIN {$wpdb->postmeta} m ON ( p.ID = m.post_id ) |
| 52 |
WHERE m.meta_key LIKE '" . WINP_Plugin::app()->getPrefix() . "snippet_type' |
| 53 |
AND p.post_type = '" . WINP_SNIPPETS_POST_TYPE . "'" ); |
| 54 |
|
| 55 |
if ( ! empty( $snippets ) ) { |
| 56 |
$i = 10; |
| 57 |
foreach ( (array) $snippets as $snippet ) { |
| 58 |
$is_snippet_priority = WINP_Helper::getMetaOption( $snippet->ID, 'snippet_priority' ); |
| 59 |
|
| 60 |
if ( ! $is_snippet_priority ) { |
| 61 |
$snippet_priority = WINP_Helper::updateMetaOption( $snippet->ID, 'snippet_priority', $i ); |
| 62 |
|
| 63 |
if ( $snippet_priority === false ) { |
| 64 |
$wpdb->insert( $wpdb->postmeta, [ |
| 65 |
'post_id' => $snippet->ID, |
| 66 |
'meta_key' => WINP_Plugin::app()->getPrefix() . 'snippet_priority', |
| 67 |
'meta_value' => $i, |
| 68 |
], [ '%d', '%s', '%s' ] ); |
| 69 |
} |
| 70 |
|
| 71 |
unset( $snippet_priority ); |
| 72 |
$i = $i + 10; |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
unset( $snippets ); |
| 78 |
} |
| 79 |
} |