public function sync($args, $assoc_args)
 {
     $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesForCurrentUser());
     WP_CLI::line('Syncing ' . MainWP_DB::num_rows($websites) . ' sites');
     $warnings = 0;
     $errors = 0;
     while ($websites && ($website = @MainWP_DB::fetch_object($websites))) {
         WP_CLI::line('  -> ' . $website->name . ' (' . $website->url . ')');
         try {
             if (MainWP_Sync::syncSite($website)) {
                 WP_CLI::success('  Sync succeeded');
             } else {
                 WP_CLI::warning('  Sync failed');
                 $warnings++;
             }
         } catch (Exception $e) {
             WP_CLI::error('  Sync failed');
             $errors++;
         }
     }
     @MainWP_DB::free_result($websites);
     if ($errors > 0) {
         WP_CLI::error('Sync completed with errors');
     } else {
         if ($warnings > 0) {
             WP_CLI::warning('Sync completed with warnings');
         } else {
             WP_CLI::success('Sync completed');
         }
     }
 }
 function prepare_items($globalIgnoredPluginConflicts = array(), $globalIgnoredThemeConflicts = array())
 {
     $this->globalIgnoredPluginConflicts = $globalIgnoredPluginConflicts;
     $this->globalIgnoredThemeConflicts = $globalIgnoredThemeConflicts;
     $orderby = 'wp.url';
     if (!isset($_GET['orderby'])) {
         $_order_by = get_option('mainwp_managesites_orderby');
         $_order = get_option('mainwp_managesites_order');
         if (!empty($_order_by)) {
             $_GET['orderby'] = $_order_by;
             $_GET['order'] = $_order;
         }
     } else {
         MainWP_Utility::update_option('mainwp_managesites_orderby', $_GET['orderby']);
         MainWP_Utility::update_option('mainwp_managesites_order', $_GET['order']);
     }
     if (isset($_GET['orderby'])) {
         if ($_GET['orderby'] == 'site') {
             $orderby = 'wp.name ' . ($_GET['order'] == 'asc' ? 'asc' : 'desc');
         } else {
             if ($_GET['orderby'] == 'url') {
                 $orderby = 'wp.url ' . ($_GET['order'] == 'asc' ? 'asc' : 'desc');
             } else {
                 if ($_GET['orderby'] == 'group') {
                     $orderby = 'GROUP_CONCAT(gr.name ORDER BY gr.name SEPARATOR ", ") ' . ($_GET['order'] == 'asc' ? 'asc' : 'desc');
                 } else {
                     if ($_GET['orderby'] == 'status') {
                         $orderby = 'CASE true
                             WHEN ((pluginConflicts <> "[]") AND (pluginConflicts IS NOT NULL) AND (pluginConflicts <> ""))
                                 THEN 1
                             WHEN (offline_check_result = -1)
                                 THEN 2
                             WHEN (wp_sync.sync_errors IS NOT NULL) AND (wp_sync.sync_errors <> "")
                                 THEN 3
                             ELSE 4
                                 + (CASE plugin_upgrades WHEN "[]" THEN 0 ELSE 1 + LENGTH(plugin_upgrades) - LENGTH(REPLACE(plugin_upgrades, "\\"Name\\":", "\\"Name\\"")) END)
                                 + (CASE theme_upgrades WHEN "[]" THEN 0 ELSE 1 + LENGTH(theme_upgrades) - LENGTH(REPLACE(theme_upgrades, "\\"Name\\":", "\\"Name\\"")) END)
                                 + (CASE wp_upgrades WHEN "[]" THEN 0 ELSE 1 END)
                         END ' . ($_GET['order'] == 'asc' ? 'asc' : 'desc');
                     } else {
                         if (isset($_REQUEST['orderby']) && $_REQUEST['orderby'] == 'last_post') {
                             $orderby = 'wp_sync.last_post_gmt ' . ($_GET['order'] == 'asc' ? 'asc' : 'desc');
                         }
                     }
                 }
             }
         }
     }
     $perPage = $this->get_items_per_page('mainwp_managesites_per_page');
     $currentPage = $this->get_pagenum();
     $no_request = !isset($_REQUEST['s']) && !isset($_REQUEST['g']) && !isset($_REQUEST['status']);
     if (!isset($_REQUEST['status'])) {
         if ($no_request) {
             $_status = get_option('mainwp_managesites_filter_status');
             if (!empty($_status)) {
                 $_REQUEST['status'] = $_status;
             }
         } else {
             MainWP_Utility::update_option('mainwp_managesites_filter_status', '');
         }
     } else {
         MainWP_Utility::update_option('mainwp_managesites_filter_status', $_REQUEST['status']);
     }
     if (!isset($_REQUEST['g'])) {
         if ($no_request) {
             $_g = get_option('mainwp_managesites_filter_group');
             if (!empty($_g)) {
                 $_REQUEST['g'] = $_g;
             }
         } else {
             MainWP_Utility::update_option('mainwp_managesites_filter_group', '');
         }
     } else {
         MainWP_Utility::update_option('mainwp_managesites_filter_group', $_REQUEST['g']);
     }
     $where = null;
     if (isset($_REQUEST['status']) && $_REQUEST['status'] != '') {
         if ($_REQUEST['status'] == 'online') {
             $where = 'wp.offline_check_result = 1';
         } else {
             if ($_REQUEST['status'] == 'offline') {
                 $where = 'wp.offline_check_result = -1';
             } else {
                 if ($_REQUEST['status'] == 'disconnected') {
                     $where = 'wp_sync.sync_errors != ""';
                 } else {
                     if ($_REQUEST['status'] == 'update') {
                         $available_update_ids = $this->get_available_update_siteids();
                         if (empty($available_update_ids)) {
                             $where = 'wp.id = -1';
                         } else {
                             $where = 'wp.id IN (' . implode(',', $available_update_ids) . ') ';
                         }
                     }
                 }
             }
         }
     }
     if (isset($_REQUEST['g']) && $_REQUEST['g'] != '') {
         $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesByGroupId($_REQUEST['g'], true));
         $totalRecords = $websites ? MainWP_DB::num_rows($websites) : 0;
         if ($websites) {
             @MainWP_DB::free_result($websites);
         }
         if (isset($_GET['orderby']) && $_GET['orderby'] == 'group') {
             $orderby = 'wp.url';
         }
         $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesByGroupId($_REQUEST['g'], true, $orderby, ($currentPage - 1) * $perPage, $perPage, $where));
     } else {
         if (isset($_REQUEST['status']) && $_REQUEST['status'] != '') {
             $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesForCurrentUser(true, null, $orderby, false, false, $where));
             $totalRecords = $websites ? MainWP_DB::num_rows($websites) : 0;
             if ($websites) {
                 @MainWP_DB::free_result($websites);
             }
             $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesForCurrentUser(true, null, $orderby, ($currentPage - 1) * $perPage, $perPage, $where));
         } else {
             $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesForCurrentUser(true, isset($_REQUEST['s']) && $_REQUEST['s'] != '' ? $_REQUEST['s'] : null, $orderby));
             $totalRecords = $websites ? MainWP_DB::num_rows($websites) : 0;
             if ($websites) {
                 @MainWP_DB::free_result($websites);
             }
             $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesForCurrentUser(true, isset($_REQUEST['s']) && $_REQUEST['s'] != '' ? $_REQUEST['s'] : null, $orderby, ($currentPage - 1) * $perPage, $perPage));
         }
     }
     $this->set_pagination_args(array('total_items' => $totalRecords, 'per_page' => $perPage));
     $this->items = $websites;
 }
示例#3
0
 public function query($sql)
 {
     if ($sql == null) {
         return false;
     }
     $result = @self::_query($sql, $this->wpdb->dbh);
     if (!$result || @MainWP_DB::num_rows($result) == 0) {
         return false;
     }
     return $result;
 }