/** * Starts the package build process * @return DUP_Package */ public function Build() { global $wp_version; global $wpdb; global $current_user; $timerStart = DUP_Util::GetMicrotime(); $this->Archive->File = "{$this->NameHash}_archive.zip"; $this->Installer->File = "{$this->NameHash}_installer.php"; $this->Database->File = "{$this->NameHash}_database.sql"; //START LOGGING DUP_Log::Open($this->NameHash); $php_max_time = @ini_get("max_execution_time"); $php_max_memory = @ini_set('memory_limit', DUPLICATOR_PHP_MAX_MEMORY); $php_max_time = $php_max_time == 0 ? "(0) no time limit imposed" : "[{$php_max_time}] not allowed"; $php_max_memory = $php_max_memory === false ? "Unabled to set php memory_limit" : DUPLICATOR_PHP_MAX_MEMORY . " ({$php_max_memory} default)"; $info = "********************************************************************************\n"; $info .= "PACKAGE-LOG: " . @date("Y-m-d H:i:s") . "\n"; $info .= "NOTICE: Do NOT post to public sites or forums \n"; $info .= "********************************************************************************\n"; $info .= "VERSION:\t" . DUPLICATOR_VERSION . "\n"; $info .= "WORDPRESS:\t{$wp_version}\n"; $info .= "PHP INFO:\t" . phpversion() . ' | ' . 'SAPI: ' . php_sapi_name() . "\n"; $info .= "SERVER:\t\t{$_SERVER['SERVER_SOFTWARE']} \n"; $info .= "PHP TIME LIMIT: {$php_max_time} \n"; $info .= "PHP MAX MEMORY: {$php_max_memory} \n"; $info .= "MEMORY STACK: " . DUP_Server::GetPHPMemory(); DUP_Log::Info($info); $info = null; //CREATE DB RECORD $packageObj = serialize($this); if (!$packageObj) { DUP_Log::Error("Unable to serialize pacakge object while building record."); } $this->ID = $this->FindHashKey($this->Hash); if ($this->ID != 0) { $this->SetStatus(DUP_PackageStatus::START); } else { $results = $wpdb->insert($wpdb->prefix . "duplicator_packages", array('name' => $this->Name, 'hash' => $this->Hash, 'status' => DUP_PackageStatus::START, 'created' => current_time('mysql', get_option('gmt_offset', 1)), 'owner' => isset($current_user->user_login) ? $current_user->user_login : '******', 'package' => $packageObj)); if ($results == false) { $error_result = $wpdb->print_error(); DUP_Log::Error("Duplicator is unable to insert a package record into the database table.", "'{$error_result}'"); } $this->ID = $wpdb->insert_id; } //START BUILD //PHPs serialze method will return the object, but the ID above is not passed //for one reason or another so passing the object back in seems to do the trick $this->Database->Build($this); $this->Archive->Build($this); $this->Installer->Build($this); //INTEGRITY CHECKS DUP_Log::Info("\n********************************************************************************"); DUP_Log::Info("INTEGRITY CHECKS:"); DUP_Log::Info("********************************************************************************"); $dbSizeRead = DUP_Util::ByteSize($this->Database->Size); $zipSizeRead = DUP_Util::ByteSize($this->Archive->Size); $exeSizeRead = DUP_Util::ByteSize($this->Installer->Size); DUP_Log::Info("SQL File: {$dbSizeRead}"); DUP_Log::Info("Installer File: {$exeSizeRead}"); DUP_Log::Info("Archive File: {$zipSizeRead} "); if (!($this->Archive->Size && $this->Database->Size && $this->Installer->Size)) { DUP_Log::Error("A required file contains zero bytes.", "Archive Size: {$zipSizeRead} | SQL Size: {$dbSizeRead} | Installer Size: {$exeSizeRead}"); } //Validate SQL files completed $sql_tmp_path = DUP_UTIL::SafePath(DUPLICATOR_SSDIR_PATH_TMP . '/' . $this->Database->File); $sql_complete_txt = DUP_Util::TailFile($sql_tmp_path, 3); if (!strstr($sql_complete_txt, 'DUPLICATOR_MYSQLDUMP_EOF')) { DUP_Log::Error("ERROR: SQL file not complete. The end of file marker was not found. Please try to re-create the package."); } $timerEnd = DUP_Util::GetMicrotime(); $timerSum = DUP_Util::ElapsedTime($timerEnd, $timerStart); $this->Runtime = $timerSum; $this->ExeSize = $exeSizeRead; $this->ZipSize = $zipSizeRead; $this->buildCleanup(); //FINAL REPORT $info = "\n********************************************************************************\n"; $info .= "RECORD ID:[{$this->ID}]\n"; $info .= "TOTAL PROCESS RUNTIME: {$timerSum}\n"; $info .= "PEAK PHP MEMORY USED: " . DUP_Server::GetPHPMemory(true) . "\n"; $info .= "DONE PROCESSING => {$this->Name} " . @date("Y-m-d H:i:s") . "\n"; DUP_Log::Info($info); DUP_Log::Close(); $this->SetStatus(DUP_PackageStatus::COMPLETE); return $this; }
/** * Starts the package build process * @return DUP_Package */ public function Build() { global $wp_version; global $wpdb; global $current_user; $timerStart = DUP_Util::GetMicrotime(); $this->Archive->File = "{$this->NameHash}_archive.zip"; $this->Installer->File = "{$this->NameHash}_installer.php"; $this->Database->File = "{$this->NameHash}_database.sql"; //START LOGGING DUP_Log::Open($this->NameHash); $php_max_time = @ini_get("max_execution_time"); $php_max_memory = @ini_set('memory_limit', DUPLICATOR_PHP_MAX_MEMORY); $php_max_time = $php_max_time == 0 ? "(0) no time limit imposed" : "[{$php_max_time}] not allowed"; $php_max_memory = $php_max_memory === false ? "Unabled to set php memory_limit" : DUPLICATOR_PHP_MAX_MEMORY . " ({$php_max_memory} default)"; $info = "********************************************************************************\n"; $info .= "PACKAGE-LOG: " . @date("Y-m-d H:i:s") . "\n"; $info .= "NOTICE: Do NOT post to public sites or forums \n"; $info .= "********************************************************************************\n"; $info .= "VERSION:\t" . DUPLICATOR_VERSION . "\n"; $info .= "WORDPRESS:\t{$wp_version}\n"; $info .= "PHP INFO:\t" . phpversion() . ' | ' . 'SAPI: ' . php_sapi_name() . "\n"; $info .= "SERVER:\t\t{$_SERVER['SERVER_SOFTWARE']} \n"; $info .= "PHP TIME LIMIT: {$php_max_time} \n"; $info .= "PHP MAX MEMORY: {$php_max_memory}"; DUP_Log::Info($info); unset($info); //CREATE DB RECORD $packageObj = serialize($this); if (!$packageObj) { DUP_Log::Error("Unable to serialize pacakge object while building record."); } $this->ID = $this->FindHashKey($this->Hash); if ($this->ID != 0) { $this->SetStatus(DUP_PackageStatus::START); } else { $results = $wpdb->insert($wpdb->prefix . "duplicator_packages", array('name' => $this->Name, 'hash' => $this->Hash, 'status' => DUP_PackageStatus::START, 'created' => current_time('mysql', get_option('gmt_offset', 1)), 'owner' => isset($current_user->user_login) ? $current_user->user_login : '******', 'package' => $packageObj)); if ($results == false) { $error_result = $wpdb->print_error(); DUP_Log::Error("Unable to insert record into database table.", "'{$error_result}'"); } $this->ID = $wpdb->insert_id; } //START BUILD //PHPs serialze method will return the object but the ID above is not passed //for one reason or another so passing the object back in seems to do the trick $this->Database->Build($this); $this->Archive->Build($this); $this->Installer->Build($this); //VALIDATE FILE SIZE $dbSizeRead = DUP_Util::ByteSize($this->Database->Size); $zipSizeRead = DUP_Util::ByteSize($this->Archive->Size); $exeSizeRead = DUP_Util::ByteSize($this->Installer->Size); if (!($this->Archive->Size && $this->Database->Size && $this->Installer->Size)) { DUP_Log::Error("A required file contains zero bytes.", "Archive Size: {$zipSizeRead} | SQL Size: {$dbSizeRead} | Installer Size: {$exeSizeRead}"); } $this->SetStatus(DUP_PackageStatus::COMPLETE); $timerEnd = DUP_Util::GetMicrotime(); $timerSum = DUP_Util::ElapsedTime($timerEnd, $timerStart); $this->Runtime = $timerSum; $this->ExeSize = $exeSizeRead; $this->ZipSize = $zipSizeRead; $this->buildCleanup(); $info = "\n********************************************************************************\n"; $info .= "RECORD ID:[{$this->ID}]\n"; $info .= "FILE SIZE: Archive:{$zipSizeRead} | SQL:{$dbSizeRead} | Installer:{$exeSizeRead}\n"; $info .= "TOTAL PROCESS RUNTIME: {$timerSum}\n"; $info .= "DONE PROCESSING => {$this->Name} " . @date("Y-m-d H:i:s") . "\n"; $info .= "********************************************************************************\n"; DUP_Log::Info($info); DUP_Log::Close(); return $this; }