function upgrade_from_0() { // Copy old tables $old = $wpdb->get_results("SELECT * FROM drainhole_files"); if (count($old) > 0) { DH_Hole::create(array('url' => get_option('drainhole_store'), 'directory' => realpath(ABSPATH) . '/' . get_option('drainhole_store'))); $hole = DH_Hole::get($wpdb->insert_id); foreach ($old as $row) { $version = $wpdb->escape($row->version); $file = $wpdb->escape($row->file); $wpdb->query("INSERT INTO {$wpdb->prefix}drainhole_files (file,hole_id,version,downloads,updated_at) VALUES ('{$file}',{$hole->id},'{$version}','{$row->downloads}',NOW())"); $file = DH_File::get($wpdb->insert_id); $file->sync_modified_time($hole); } } // Delete old tables $wpdb->query("DROP TABLE drainhole_files"); $wpdb->query("DROP TABLE drainhole_access"); }
function screen_holes() { if (isset($_POST['create']) && check_admin_referer('drainhole-new_hole')) { $_POST = stripslashes_deep($_POST); if (($result = DH_Hole::create($_POST)) === true) { DH_Hole::flush(); $this->render_message(__('The Drain Hole was successfully created', 'drain-hole')); do_action('drainhole_hole_created'); } else { $this->render_message(__('The Drain Hole was not created - ', 'drain-hole') . $result); } // Cache the list of holes so we don't need to access the database $holes = DH_Hole::get_as_list(); } $base_url = rtrim(get_bloginfo('home'), '/') . '/download'; $base_directory = $this->realpath(rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/download') . '/'; $pager = new DH_Pager($_GET, $_SERVER['REQUEST_URI'], 'name', 'ASC'); $this->render_admin('holes', array('holes' => DH_Hole::get_all($pager), 'pager' => $pager, 'options' => $this->get_options(), 'base_url' => $base_url, 'base_directory' => $base_directory, 'home' => get_bloginfo('home'))); }