/** * Load the View */ public function onLoad() { needRole(RDR_User::ROLE_ADMIN, true); $this->form = $this->getForm(); if (post("save")) { foreach ($this->form->fields as $field) { if ($field->attr->get("data-setting")) { RDR_Setting::set($field->name, $field->getSubmittedValue()); } } v("message", t("saved")); $this->form = $this->getForm(); } view("RDR_BasicFrame", array("view" => $this)); }
/** * Load the View */ public function onLoad() { if (req()->isAjax() && get("code") == self::getValidHash()) { $data = null; switch (get("action")) { case "update-check": # fetching branches from GIT $data = array("error" => t("update.4")); $branches = self::getGitJSON("https://api.github.com/repos/brainfoolong/nreeda/branches"); if ($branches) { $newest = null; foreach ($branches as $branch) { if ($branch["name"] == "master") { continue; } if (!$newest || version_compare($branch["name"], $newest, ">")) { $newest = $branch["name"]; } } $data = array("version" => $newest, "update" => version_compare($newest, RDR_VERSION, ">")); RDR_Setting::set("latestversion", $newest); } break; case "start": if (RDR_Cron::isRunning()) { $data = array("message" => t("update.1"), "event" => "error"); } else { RDR_Maintenance::enableMaintenanceMode(); $data = array("message" => sprintf(nl2br(t("update.2"), true), url()->getByAlias("root", l("RDR_Maintenance")) . '?disable-maintenance=' . RDR_Maintenance::getValidHash(), 'RDR::$maintenanceMode = true'), "event" => "success", "next" => "check"); } break; case "check": try { # checking all files and directories for write access $files = CHOQ_FileManager::getFiles(CHOQ_ROOT_DIRECTORY, true, true); $count = 0; $files[] = CHOQ_ROOT_DIRECTORY; foreach ($files as $file) { if (substr($file, 0, 1) == ".") { continue; } if (!is_writable($file)) { $count++; } } if ($count) { error(sprintf(t("update.3"), $count)); } $version = RDR_Setting::get("latestversion")->value; $data = array("message" => sprintf(t("update.5"), $version), "event" => "success", "next" => "prepare", "params" => array("version" => $version)); } catch (Exception $e) { $data = array("message" => sprintf(t("update.7"), $e->getMessage()), "event" => "error"); } break; case "prepare": try { # downloading zip file from GIT $url = "https://github.com/brainfoolong/nreeda/archive/" . get("version") . ".zip"; $data = RDR_FileContents::get($url); if ($data === false) { return; } $tmpZip = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/update.zip"; file_put_contents($tmpZip, $data); $updateDir = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/update"; if (!is_dir($updateDir)) { mkdir($updateDir); } # removing all old files $files = CHOQ_FileManager::getFiles($updateDir, true, true); foreach ($files as $file) { if (!is_dir($file)) { unlink($file); } } foreach ($files as $file) { if (is_dir($file)) { rmdir($file); } } # extract zip file to tmp folder $zip = new ZipArchive(); $zip->open($tmpZip); $zip->extractTo($updateDir); $zip->close(); $folder = $updateDir . "/nreeda-" . get("version"); $data = array("message" => t("update.9"), "event" => "success", "next" => "update", "params" => array("updatefolder" => $folder, "rootfolder" => CHOQ_ROOT_DIRECTORY, "updateurl" => url()->getByAlias("base", "modules/RDR/tmp/update/nreeda-" . get("version") . "/update.php"))); } catch (Exception $e) { $data = array("message" => sprintf(t("update.7"), $e->getMessage()), "event" => "error"); } break; case "db": try { RDR_DBUpdate::run(); $data = array("message" => t("update.10"), "event" => "success", "next" => "cleanup"); } catch (Exception $e) { $data = array("message" => sprintf(t("update.7"), $e->getMessage()), "event" => "error"); } break; case "cleanup": try { # deleting all update files $updateDir = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/update"; if (is_dir($updateDir)) { $files = CHOQ_FileManager::getFiles($updateDir, true, true); foreach ($files as $file) { if (!is_dir($file)) { unlink($file); } } foreach ($files as $file) { if (is_dir($file)) { rmdir($file); } } } if (is_dir($updateDir)) { rmdir($updateDir); } $updateFile = CHOQ_ROOT_DIRECTORY . "/update.php"; if (file_exists($updateFile)) { unlink($updateFile); } $data = array("message" => t("update.11"), "event" => "success"); } catch (Exception $e) { $data = array("message" => sprintf(t("update.7"), $e->getMessage()), "event" => "error"); } break; case "disable": RDR_Maintenance::disableMaintenanceMode(); break; } echo json_encode($data); return; } needRole(RDR_User::ROLE_ADMIN, true); view("RDR_BasicFrame", array("view" => $this)); }