/** * Add content files and directories * * @return void */ public function content() { // Total and processed files $total = Ai1wm_Status::get('total'); $processed = Ai1wm_Status::get('processed'); $progress = (int) ($processed / $total * 100) or $progress = 4; // Set progress Ai1wm_Status::set(array('type' => 'info', 'message' => sprintf(__('Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME), $total, $progress))); // Start time $start = microtime(true); // Flag to hold if all files have been processed $completed = true; // Open the archive file for reading $archive = new Ai1wm_Extractor($this->storage()->archive()); // Set the file pointer to the one that we have saved $archive->set_file_pointer(null, $this->pointer()); while ($archive->has_not_reached_eof()) { // Extract a file from archive to wp_content_dir $archive->extract_one_file_to(WP_CONTENT_DIR, array(AI1WM_PACKAGE_NAME, AI1WM_DATABASE_NAME)); // Increment processed files counter $processed++; // We are only extracting files for 5 seconds at a time $time = microtime(true) - $start; if ($time > 5) { // More than 5 seconds have passed, break and do another request $completed = false; break; } } // Set new file map pointer $this->pointer($archive->get_file_pointer()); // Close the archive file $archive->close(); // Set progress Ai1wm_Status::set(array('processed' => $processed)); // Redirect if ($completed) { $this->route_to('database'); } else { $this->route_to('content'); } }
/** * Add content files and directories * * @return void */ public function content() { // Total and processed files $total = (int) Ai1wm_Status::get('total'); $processed = (int) Ai1wm_Status::get('processed'); // What percent of files have we processed? $progress = @(int) ($processed / $total * 100); // Set progress Ai1wm_Status::set(array('message' => sprintf(__('Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME), $total, $progress))); // Get map file $filemap = fopen($this->storage()->filemap(), 'r'); // Start time $start = microtime(true); // Flag to hold if all files have been processed $completed = true; // Set file map pointer at the current index if (fseek($filemap, $this->pointer()) !== -1) { // Get archive $archive = new Ai1wm_Compressor($this->storage()->archive()); while ($path = trim(fgets($filemap))) { try { // Add file to archive $archive->add_file(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $path, $path); } catch (Exception $e) { // Skip bad file permissions } $processed++; // time elapsed $time = microtime(true) - $start; if ($time > 3) { // More than 3 seconds have passed, break and do another request $completed = false; break; } } $archive->close(); } // Set new file map pointer $this->pointer(ftell($filemap)); fclose($filemap); // Set progress Ai1wm_Status::set(array('processed' => $processed)); // Redirect if ($completed) { // Redirect $this->route_to('database'); } else { $this->route_to('content'); } }