Esempio n. 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));
 }
Esempio n. 2
0
    /**
     * Get content
     */
    public function getContent()
    {
        headline(t("admin.update.cron.title"));
        ?>
        <div class="indent">
            <?php 
        echo nl2br(t("admin.update.cron.text"));
        ?>
<br/>
            <code style="font-size: 11px;">*/10 * * * * php -f <?php 
        echo escapeshellarg(CHOQ_ROOT_DIRECTORY . DIRECTORY_SEPARATOR . "console.php");
        ?>
 <?php 
        echo escapeshellarg("cron");
        ?>
</code>
        </div>
        <div class="spacer"></div>

        <?php 
        headline(t("admin.update.webcron.title"));
        ?>
        <div class="indent">
            <?php 
        echo nl2br(t("admin.update.webcron.text"));
        ?>
<br/>
            <code style="font-size: 11px;"><a href="<?php 
        echo RDR_Cron::getLink();
        ?>
" target="_blank"><?php 
        echo RDR_Cron::getLink();
        ?>
</a></code>
        </div>
        <div class="spacer"></div>

        <?php 
        headline(t("admin.update.3"));
        ?>
        <div class="indent">
            <?php 
        echo t("admin.update.4");
        ?>
.<br/><br/>
            <div class="btn update-all"><?php 
        echo t("admin.update.5");
        ?>
</div>
            <div class="spacer"></div>
            <?php 
        $feeds = RDR_Feed::getByCondition(null, null, "+name");
        foreach ($feeds as $feed) {
            ?>
                <div style="padding-left: 20px; margin-bottom: 2px;" class="feed">
                    <div class="inline-btn update-feed" data-id="<?php 
            echo $feed->getId();
            ?>
"><?php 
            echo t("admin.update.6");
            ?>
</div>
                    <div class="inline-btn delete-feed" data-id="<?php 
            echo $feed->getId();
            ?>
"><?php 
            echo t("organize.15");
            ?>
</div>
                    <img src="<?php 
            echo url()->getByAlias("public", "img/loading-2.gif");
            ?>
" alt="" style="position: relative; top:2px; display: none;" class="loading-feed"/>
                    <a href="<?php 
            echo $feed->getLink();
            ?>
"><?php 
            echo s($feed->name);
            ?>
</a><br/>
                    <div class="small" style="margin-top:3px;"><a href="<?php 
            echo s($feed->url);
            ?>
"><?php 
            echo s($feed->url);
            ?>
</a></div>
                </div>
            <?php 
        }
        ?>
        </div>

        <script type="text/javascript">
        (function(){
            $("#content div.update-feed.inline-btn").on("click", function(){
                $("img.loading-feed").hide();
                pipeline = [$(this).attr("data-id")];
                runUpdate();
            });
            $("#content div.delete-feed.inline-btn").on("click", function(){
                if(confirm(<?php 
        echo json_encode(t("organize.13"));
        ?>
)){
                    API.req("delete-feed-admin", {"fid" : $(this).attr("data-id")});
                    $(this).closest(".feed").remove();
                }
            });
            $("#content div.update-all").on("click", function(){
                $("#content img.loading-feed").hide();
                pipeline = [];
                $("#content div.update-feed.inline-btn").each(function(){
                    pipeline.push($(this).attr("data-id"));
                });
                runUpdate();
            });

            var pipeline = [];
            function runUpdate(){
                if(!pipeline.length) {
                    Global.updateNewsCache();
                    return;
                }
                var id = pipeline.shift();
                var btn = $("#content div.update-feed[data-id='"+id+"']").parent().find(".loading-feed");
                btn.show();
                $.post('<?php 
        echo url()->getUri();
        ?>
', {"update" : id}, function(){
                    btn.hide();
                    runUpdate();
                });
            }
        })();
        </script>
        <?php 
    }