function sns_backup_external_restore($uname) { try { Sns_Log::log_msg('########PROCESS STARTED########' . PHP_EOL); $state = Sns_State::get_status(); if ($state['status'] == Sns_State::STATUS_ACTIVE) { throw new Sns_Exception_Unavailable_Operation('There is an existing active process.Please wait.'); } $stateData = array('status' => Sns_State::STATUS_ACTIVE, 'type' => Sns_State::TYPE_RESTORE, 'start_date' => date('Y-m-d H:i:s')); Sns_State::update($stateData); try { $file_dir = dirname(__FILE__) . SNS_DS . 'sns_backup-external-' . $uname . '.zip'; if (!file_exists($file_dir)) { throw new Sns_Exception_Not_Found('File not found'); } $backup_dir = substr($file_dir, 0, strlen($file_dir) - 4); Sns_Log::log_action('Restoring from external file'); Sns_History::restore_from_file($backup_dir, $file_dir); Sns_Log::log_action('Restoring from external file', SNS_LOG_END); @unlink($file_dir); Sns_Log::log_msg('[SUCCEED Restore]' . PHP_EOL); } catch (Exception $e) { Sns_Log::log_msg('[FAILED Restore]' . PHP_EOL); throw $e; } $stateData = array('status' => Sns_State::STATUS_FINISHED, 'type' => Sns_State::TYPE_RESTORE); Sns_State::update($stateData); Sns_Log::log_msg('########PROCESS ENDED########' . PHP_EOL); } catch (Exception $e) { Sns_Log::log_exception_obj($e); $ex_data = Sns_Exception_Handler::get_exception_data($e); $stateData = array('status' => Sns_State::STATUS_FAILED, 'type' => Sns_State::TYPE_RESTORE, 'msg' => $ex_data['status'] . ' : ' . $ex_data['msg']); Sns_State::update($stateData); Sns_Log::log_msg('########PROCESS ENDED########' . PHP_EOL); Sns_Log::report('restore'); wp_redirect(admin_url("admin.php?page=" . $_GET['page'])); } }