public function status($step = 0) { $this->template = ""; $this->auto_render = FALSE; $url = $this->release->download; $working_dir = Kohana::config('upload.relative_directory') . "/upgrade/"; $zip_file = Kohana::config('upload.relative_directory') . "/upgrade/ushahidi.zip"; if ($step == 0) { $this->upgrade->logger("Downloading latest version of ushahidi..."); echo json_encode(array("status" => "success", "message" => Kohana::lang('upgrade.download'))); } if ($step == 1) { // Create the Directory if it doesn't exist if (!file_exists(DOCROOT . "media/uploads/upgrade")) { mkdir(DOCROOT . "media/uploads/upgrade"); chmod(DOCROOT . "media/uploads/upgrade", 0777); $this->upgrade->logger("Creating Directory - " . DOCROOT . "media/uploads/upgrade"); } $latest_ushahidi = $this->upgrade->download_ushahidi($url); //download was successful if ($this->upgrade->success) { $this->upgrade->write_to_file($latest_ushahidi, $zip_file); $this->upgrade->logger("Successfully Downloaded. Unpacking " . $zip_file); echo json_encode(array("status" => "success", "message" => Kohana::lang('upgrade.successfully_downloaded'))); } else { $this->upgrade->logger("** Failed downloading.\n\n"); echo json_encode(array("status" => "error", "message" => Kohana::lang('upgrade.failed_downloading'))); } } if ($step == 2) { //extract compressed file $this->upgrade->unzip_ushahidi($zip_file, $working_dir); //extraction was successful if ($this->upgrade->success) { $this->upgrade->logger("Successfully Unpacked. Copying files..."); echo json_encode(array("status" => "success", "message" => Kohana::lang('upgrade.successfully_unpacked'))); } else { $this->upgrade->logger("** Failed unpacking.\n\n"); echo json_encode(array("status" => "error", "message" => Kohana::lang('upgrade.failed_unpacking'))); } } if ($step == 3) { //copy files $this->upgrade->ftp_recursively($working_dir . "ushahidi/", DOCROOT); $this->upgrade->remove_old($working_dir . 'ushahidi/upgrader_removed_files.txt', DOCROOT); // Clear out caches before new request Cache::instance()->delete_all(); Kohana::cache_save('configuration', NULL, Kohana::config('core.internal_cache')); Kohana::cache_save('language', NULL, Kohana::config('core.internal_cache')); Kohana::cache_save('find_file_paths', NULL, Kohana::config('core.internal_cache')); Event::clear('system.shutdown', array('Kohana', 'internal_cache_save')); //copying was successful if ($this->upgrade->success) { $this->upgrade->logger("Successfully Copied. Upgrading Database..."); echo json_encode(array("status" => "success", "message" => Kohana::lang('upgrade.successfully_copied'))); } else { $this->upgrade->logger("** Failed copying files.\n\n"); echo json_encode(array("status" => "error", "message" => Kohana::lang('upgrade.failed_copying'))); } } // Database BACKUP + UPGRADE if ($step == 4) { // backup database. // is gzip enabled ? $gzip = Kohana::config('config.output_compression'); $error = $this->_do_db_backup($gzip); if (empty($error)) { if (file_exists(DOCROOT . "sql/")) { $this->_process_db_upgrade(DOCROOT . "sql/"); } $this->upgrade->logger("Database backup and upgrade successful."); echo json_encode(array("status" => "success", "message" => Kohana::lang('upgrade.backup_success'))); } else { $this->upgrade->logger("** Failed backing up database.\n\n"); echo json_encode(array("status" => "error", "message" => Kohana::lang('upgrade.backup_failed'))); } } // Database UPGRADE ONLY if ($step == 5) { if (file_exists(DOCROOT . "sql/")) { //upgrade tables $this->_process_db_upgrade(DOCROOT . "sql/"); $this->upgrade->logger("Database upgrade successful."); echo json_encode(array("status" => "success", "message" => Kohana::lang('upgrade.dbupgrade_success'))); } else { $this->upgrade->logger("Database upgrade successful."); echo json_encode(array("status" => "success", "message" => Kohana::lang('upgrade.dbupgrade_success'))); } } // Delete downloaded files if ($step == 6) { $this->upgrade->logger("Deleting downloaded files..."); echo json_encode(array("status" => "success", "message" => Kohana::lang('upgrade.deleting_files'))); } if ($step == 7) { $this->upgrade->remove_recursively($working_dir); $this->upgrade->logger("UPGRADE SUCCESSFUL"); echo json_encode(array("status" => "success", "message" => Kohana::lang('upgrade.upgrade_success', array(url::site("admin/upgrade/logfile?f=" . $this->session->get('upgrade_session') . ".txt"))))); $this->session->delete('upgrade_session'); } }
/** * Saves a cached version of this configuration driver * * @return bool * @access public */ public function save_cache() { // If this configuration has changed if ($this->get('core.internal_cache') !== FALSE and $this->changed) { $data = $this->config; // Save the cache return Kohana::cache_save($this->cache_name, $data, $this->cache_lifetime); } return TRUE; }
/** * Saves the internal caches: configuration, include paths, etc. * * @return boolean */ public static function internal_cache_save() { if (!is_array(Kohana::$write_cache)) { return FALSE; } // Get internal cache names $caches = array_keys(Kohana::$write_cache); // Nothing written $written = FALSE; foreach ($caches as $cache) { if (isset(Kohana::$internal_cache[$cache])) { // Write the cache file Kohana::cache_save($cache, Kohana::$internal_cache[$cache], Kohana::config('core.internal_cache')); // A cache has been written $written = TRUE; } } return $written; }