示例#1
0
 /**
  * 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));
 }
示例#2
0
 /**
  * Load the View
  */
 public function onLoad()
 {
     if (!inNormalMode()) {
         return;
     }
     # set time limit to max 10 minutes
     # if this limit is reached than the script stops and continue at next cron
     set_time_limit(RDR_Cron::MAXTIME);
     $cronPidFile = self::getPIDFile();
     # skip when cron is already running
     if (self::isRunning()) {
         RDR_Event::log(RDR_Event::TYPE_CRON_RUNNING);
         return;
     }
     # create a tmp file that show us the cron pid
     file_put_contents($cronPidFile, time());
     $param = $this->getParam("param");
     if ($param != self::getHash()) {
         die("Not allowed");
     }
     RDR_Event::log(RDR_Event::TYPE_CRON_START);
     RDR_Import::updateAllFeeds();
     RDR_Event::log(RDR_Event::TYPE_CRON_END);
     RDR_Cleanup::cleanupEvents();
     RDR_Cleanup::cleanupEntries();
     RDR_FileContents::cleanupTmpFiles();
     RDR_Proxy::cleanupTmpFiles();
     # optimizing tables
     $generator = CHOQ_DB_Generator::create(db());
     if ($generator instanceof CHOQ_DB_Generator_Mysql) {
         $generator->addModule("RDR");
         $generator->optimizeTables();
     }
     # delete tmp file that show us the cron pid
     unlink(CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/cron.pid");
 }
示例#3
0
 /**
  * Get Simple xml from a feed url
  *
  * @param mixed $url
  * @return SimpleXMLElement | bool
  */
 private static function getSimpleXMLFromUrl($url)
 {
     $data = RDR_FileContents::get($url);
     if ($data === false) {
         return false;
     }
     $xml = @simplexml_load_string($data, null, LIBXML_NOCDATA);
     if (!$xml) {
         RDR_Event::log(RDR_Event::TYPE_SIMPLEXML_ERROR, array("text" => $url));
         return false;
     }
     return $xml;
 }