/** * Previous Imports list */ public function index() { $get = $this->input->get(array('s' => '', 'order_by' => 'registered_on', 'order' => 'DESC', 'pagenum' => 1, 'perPage' => 25)); $get['pagenum'] = absint($get['pagenum']); extract($get); $this->data += $get; if (!in_array($order_by, array('registered_on', 'id', 'name'))) { $order_by = 'registered_on'; } if (!in_array($order, array('DESC', 'ASC'))) { $order = 'DESC'; } $list = new PMXI_Import_List(); $post = new PMXI_Post_Record(); $by = array('parent_import_id' => 0); if ('' != $s) { $like = '%' . preg_replace('%\\s+%', '%', preg_replace('/[%?]/', '\\\\$0', $s)) . '%'; $by[] = array(array('name LIKE' => $like, 'type LIKE' => $like, 'path LIKE' => $like, 'friendly_name LIKE' => $like), 'OR'); } $this->data['list'] = $list->join($post->getTable(), $list->getTable() . '.id = ' . $post->getTable() . '.import_id', 'LEFT')->setColumns($list->getTable() . '.*', 'COUNT(' . $post->getTable() . '.post_id' . ') AS post_count')->getBy($by, "{$order_by} {$order}", $pagenum, $perPage, $list->getTable() . '.id'); $this->data['page_links'] = paginate_links(array('base' => add_query_arg('pagenum', '%#%', $this->baseUrl), 'add_args' => array('page' => 'pmxi-admin-manage'), 'format' => '', 'prev_text' => __('«', 'wp_all_import_plugin'), 'next_text' => __('»', 'wp_all_import_plugin'), 'total' => ceil($list->total() / $perPage), 'current' => $pagenum)); //pmxi_session_unset(); PMXI_Plugin::$session->clean_session(); $this->render(); }
function pmxi_wpmu_new_blog($blog_id, $user_id, $domain, $path, $site_id, $meta) { // create/update required database tables require_once ABSPATH . 'wp-admin/includes/upgrade.php'; require PMXI_Plugin::ROOT_DIR . '/schema.php'; global $wpdb; if (function_exists('is_multisite') && is_multisite()) { // check if it is a network activation - if so, run the activation function for each blog id $old_blog = $wpdb->blogid; switch_to_blog($blog_id); require PMXI_Plugin::ROOT_DIR . '/schema.php'; dbDelta($plugin_queries); // sync data between plugin tables and wordpress (mostly for the case when plugin is reactivated) $post = new PMXI_Post_Record(); $wpdb->query('DELETE FROM ' . $post->getTable() . ' WHERE post_id NOT IN (SELECT ID FROM ' . $wpdb->posts . ')'); switch_to_blog($old_blog); return; } }
/** * Plugin activation logic */ public function __activation() { // uncaught exception doesn't prevent plugin from being activated, therefore replace it with fatal error so it does set_exception_handler(create_function('$e', 'trigger_error($e->getMessage(), E_USER_ERROR);')); // create plugin options $option_name = get_class($this) . '_Options'; $options_default = PMXI_Config::createFromFile(self::ROOT_DIR . '/config/options.php')->toArray(); $wpai_options = get_option($option_name, false); if (!$wpai_options) { update_option($option_name, $options_default); } // create/update required database tables require_once ABSPATH . 'wp-admin/includes/upgrade.php'; require self::ROOT_DIR . '/schema.php'; global $wpdb; if (function_exists('is_multisite') && is_multisite()) { // check if it is a network activation - if so, run the activation function for each blog id if (isset($_GET['networkwide']) && $_GET['networkwide'] == 1) { $old_blog = $wpdb->blogid; // Get all blog ids $blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}"); foreach ($blogids as $blog_id) { switch_to_blog($blog_id); require self::ROOT_DIR . '/schema.php'; dbDelta($plugin_queries); // sync data between plugin tables and wordpress (mostly for the case when plugin is reactivated) $post = new PMXI_Post_Record(); $wpdb->query('DELETE FROM ' . $post->getTable() . ' WHERE post_id NOT IN (SELECT ID FROM ' . $wpdb->posts . ')'); } switch_to_blog($old_blog); return; } } dbDelta($plugin_queries); // sync data between plugin tables and wordpress (mostly for the case when plugin is reactivated) $post = new PMXI_Post_Record(); $wpdb->query('DELETE FROM ' . $post->getTable() . ' WHERE post_id NOT IN (SELECT ID FROM ' . $wpdb->posts . ')'); }
public function __fix_db_schema() { $uploads = wp_upload_dir(); if (!is_dir($uploads['basedir'] . DIRECTORY_SEPARATOR . self::LOGS_DIRECTORY) or !is_writable($uploads['basedir'] . DIRECTORY_SEPARATOR . self::LOGS_DIRECTORY)) { die(sprintf(__('Uploads folder %s must be writable', 'wp_all_import_plugin'), $uploads['basedir'] . DIRECTORY_SEPARATOR . self::LOGS_DIRECTORY)); } if (!is_dir($uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_IMPORT_UPLOADS_BASE_DIRECTORY) or !is_writable($uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_IMPORT_UPLOADS_BASE_DIRECTORY)) { die(sprintf(__('Uploads folder %s must be writable', 'wp_all_import_plugin'), $uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_IMPORT_UPLOADS_BASE_DIRECTORY)); } // create/update required database tables require_once ABSPATH . 'wp-admin/includes/upgrade.php'; require self::ROOT_DIR . '/schema.php'; global $wpdb; if (function_exists('is_multisite') && is_multisite()) { // check if it is a network activation - if so, run the activation function for each blog id if (isset($_GET['networkwide']) && $_GET['networkwide'] == 1) { $old_blog = $wpdb->blogid; // Get all blog ids $blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}"); foreach ($blogids as $blog_id) { switch_to_blog($blog_id); require self::ROOT_DIR . '/schema.php'; dbDelta($plugin_queries); // sync data between plugin tables and wordpress (mostly for the case when plugin is reactivated) $post = new PMXI_Post_Record(); $wpdb->query('DELETE FROM ' . $post->getTable() . ' WHERE post_id NOT IN (SELECT ID FROM ' . $wpdb->posts . ')'); } switch_to_blog($old_blog); return; } } dbDelta($plugin_queries); // do not execute ALTER TABLE queries if sql user doesn't have ALTER privileges $grands = $wpdb->get_results("SELECT * FROM information_schema.user_privileges WHERE grantee LIKE \"'" . DB_USER . "'%\" AND PRIVILEGE_TYPE = 'ALTER' AND IS_GRANTABLE = 'YES';"); $table = $table = $this->getTablePrefix() . 'files'; $tablefields = $wpdb->get_results("DESCRIBE {$table};"); // For every field in the table foreach ($tablefields as $tablefield) { if ('contents' == $tablefield->Field) { $list = new PMXI_File_List(); for ($i = 1; $list->getBy(NULL, 'id', $i, 1)->count(); $i++) { foreach ($list->convertRecords() as $file) { $file->save(); // resave file for file to be stored in uploads folder } } if (!empty($grands)) { $wpdb->query("ALTER TABLE {$table} DROP " . $tablefield->Field); } break; } } $table = $this->getTablePrefix() . 'imports'; $tablefields = $wpdb->get_results("DESCRIBE {$table};"); $fields_to_alter = array('parent_import_id', 'iteration', 'deleted', 'executing', 'canceled', 'canceled_on', 'failed', 'failed_on', 'settings_update_on', 'last_activity'); // Check if field exists foreach ($tablefields as $tablefield) { if (in_array($tablefield->Field, $fields_to_alter)) { $fields_to_alter = array_diff($fields_to_alter, array($tablefield->Field)); } } if (!empty($fields_to_alter)) { if (empty($grands)) { return false; } foreach ($fields_to_alter as $field) { switch ($field) { case 'parent_import_id': $wpdb->query("ALTER TABLE {$table} ADD `parent_import_id` BIGINT(20) NOT NULL DEFAULT 0;"); break; case 'iteration': $wpdb->query("ALTER TABLE {$table} ADD `iteration` BIGINT(20) NOT NULL DEFAULT 0;"); break; case 'deleted': $wpdb->query("ALTER TABLE {$table} ADD `deleted` BIGINT(20) NOT NULL DEFAULT 0;"); break; case 'executing': $wpdb->query("ALTER TABLE {$table} ADD `executing` BOOL NOT NULL DEFAULT 0;"); break; case 'canceled': $wpdb->query("ALTER TABLE {$table} ADD `canceled` BOOL NOT NULL DEFAULT 0;"); break; case 'canceled_on': $wpdb->query("ALTER TABLE {$table} ADD `canceled_on` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';"); break; case 'failed': $wpdb->query("ALTER TABLE {$table} ADD `failed` BOOL NOT NULL DEFAULT 0;"); break; case 'failed_on': $wpdb->query("ALTER TABLE {$table} ADD `failed_on` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';"); break; case 'settings_update_on': $wpdb->query("ALTER TABLE {$table} ADD `settings_update_on` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';"); break; case 'last_activity': $wpdb->query("ALTER TABLE {$table} ADD `last_activity` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';"); break; default: # code... break; } } } $table = $this->getTablePrefix() . 'posts'; $tablefields = $wpdb->get_results("DESCRIBE {$table};"); $iteration = false; $specified = false; // Check if field exists foreach ($tablefields as $tablefield) { if ('iteration' == $tablefield->Field) { $iteration = true; } if ('specified' == $tablefield->Field) { $specified = true; } } if (!$iteration) { if (empty($grands)) { ?> <div class="error"><p> <?php printf(__('<b>%s Plugin</b>: Current sql user %s doesn\'t have ALTER privileges', 'pmwi_plugin'), self::getInstance()->getName(), DB_USER); ?> </p></div> <?php return false; } $wpdb->query("ALTER TABLE {$table} ADD `iteration` BIGINT(20) NOT NULL DEFAULT 0;"); } if (!$specified and !empty($grands)) { $wpdb->query("ALTER TABLE {$table} ADD `specified` BOOL NOT NULL DEFAULT 0;"); } if (!empty($wpdb->charset)) { $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $charset_collate .= " COLLATE {$wpdb->collate}"; } $table_prefix = $this->getTablePrefix(); $wpdb->query("CREATE TABLE IF NOT EXISTS {$table_prefix}history (\n\t\t\tid BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\timport_id BIGINT(20) UNSIGNED NOT NULL,\n\t\t\ttype ENUM('manual','processing','trigger','continue','') NOT NULL DEFAULT '',\t\n\t\t\ttime_run TEXT,\t\n\t\t\tdate DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\t\t\n\t\t\tsummary TEXT,\n\t\t\tPRIMARY KEY (id)\n\t\t) {$charset_collate};"); return true; }