/**
  * Do the database update
  */
 static function run()
 {
     $generator = CHOQ_DB_Generator::create(db());
     $generator->addModule("RDR");
     $generator->updateDatabase();
     # setting current version
     $setting = RDR_Setting::get("dbversion");
     $setting->value = RDR_VERSION;
     $setting->store();
 }
Exemple #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");
 }
Exemple #3
0
    /**
     * Get content
     */
    public function getContent()
    {
        $errors = $checkErrors = array();
        $writeableFolders = array(CHOQ_ACTIVE_MODULE_DIRECTORY, CHOQ_ACTIVE_MODULE_DIRECTORY . "/public/static", CHOQ_ACTIVE_MODULE_DIRECTORY . "/public/img/favicons", CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp");
        foreach ($writeableFolders as $folder) {
            if (!is_dir($folder)) {
                $errors[] = sprintf(t("install.folder.notexist"), $folder);
                break;
            }
            if (!is_writable($folder)) {
                $errors[] = sprintf(t("install.folder.writeable"), $folder);
                break;
            }
        }
        if (!ini_get("allow_url_fopen")) {
            $errors[] = sprintf(t("install.php.feature"), "allow_url_fopen");
        }
        if (!function_exists("fsockopen")) {
            $errors[] = sprintf(t("install.php.feature"), "fsockopen/sockets");
        }
        if (!function_exists("simplexml_load_file")) {
            $errors[] = sprintf(t("install.php.feature"), "SimpleXML");
        }
        if (!CHOQ_DB_Mysql::isAvailable()) {
            $errors[] = sprintf(t("install.php.feature"), "MySQLi");
        }
        if (post("install")) {
            try {
                $connString = "mysql://" . post("mysql-user") . ":" . post("mysql-pass") . "@" . post("mysql-host") . "/" . post("mysql-db");
                CHOQ_DB::add($connString, "test");
                db("test")->query("DROP TABLE IF EXISTS " . db("test")->quote("RDR_test"));
                db("test")->query("CREATE TABLE " . db("test")->quote("RDR_test") . " (" . db("test")->quote("id") . " INT NOT NULL)");
                db("test")->query("DROP TABLE IF EXISTS " . db("test")->quote("RDR_test"));
                $fileData = "<?php\nif(!defined(\"CHOQ\")) die();\n/**\n * Local Configuration\n**/\n\n";
                $fileData .= 'CHOQ_DB::add(\'' . $connString . '\');' . "\n";
                $fileData .= 'v("hash.salt", "' . uniqid(NULL, true) . sha1(microtime() . uniqid(NULL, true)) . '");' . "\n";
                $tmpfile = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/_RDR.local.tmp.php";
                file_put_contents($tmpfile, $fileData);
                include $tmpfile;
                $generator = CHOQ_DB_Generator::create(db());
                $tables = $generator->getExistingTables();
                foreach ($tables as $table) {
                    if ($table == "_choqled_metadata" || substr(strtolower($table), 0, 3) == "rdr_") {
                        db()->query("DROP TABLE " . db()->quote($table));
                    }
                }
                RDR_DBUpdate::run();
                $user = new RDR_User(db());
                $user->username = post("admin-user");
                $user->setPassword(post("admin-pass"));
                $user->role = RDR_User::ROLE_ADMIN;
                $user->store();
                rename($tmpfile, CHOQ_ACTIVE_MODULE_DIRECTORY . "/_RDR.local.php");
                redirect(url()->getByAlias("base"));
            } catch (Exception $e) {
                $checkErrors[] = $e->getMessage();
            }
        }
        ?>
        <div class="center">
            <img src="<?php 
        echo url()->getByAlias("public", "img/logo-1.png");
        ?>
" alt=""/>
        </div>
        <?php 
        if (!$errors) {
            $this->showErrors($checkErrors);
            $form = $this->getForm();
            $formTable = new Form_Table($form);
            $formTable->addSubmit(t("install.finish"));
            echo $formTable->getHtml();
            echo "<div class='center'><br/>" . t("install.warn") . "</div>";
        } else {
            $this->showErrors($errors);
        }
    }