function __construct($pharName) { echo "<pre>"; $buildRoot = realpath(Ruth::getDOCUMENT_ROOT() . "/../build"); $srcRoot = realpath(Ruth::getDOCUMENT_ROOT()); echo "Building {$pharName}.phar to " . $buildRoot . "\n"; echo "Source: {$srcRoot} \n"; echo "Have you cleaned up the path yet ?"; //clean up things $phar = new Phar($buildRoot . "/" . $pharName . ".phar", FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, $pharName . ".phar"); $phar["index.php"] = file_get_contents($srcRoot . "/index.php"); $phar->buildFromDirectory($srcRoot); $phar->setStub('<?php Phar::webPhar(); __HALT_COMPILER();'); echo "<pre>"; }
/** * The constructor for Reta * @param String $reportPath Relative to the document root * @param String $outputPath Relative to the document root * @param String $iniFile Path to the iniFile, normally is in the same folder as reta, but you may want more. * @param String $retaPath Path to reta if the system can't determine it, usually one folder below the document root */ function __construct($reportPath = "reports", $outputPath = "output", $iniFile = "reta.ini", $retaPath = "") { $this->reportPath = Ruth::getDOCUMENT_ROOT() . "/" . $reportPath; $this->outputPath = Ruth::getDOCUMENT_ROOT() . "/" . $outputPath; $this->iniFile = $iniFile; if (empty($retaPath)) { $this->retaPath = realpath(Ruth::getDOCUMENT_ROOT() . '/../reta') . '/reta.exe'; $this->iniFile = realpath(Ruth::getDOCUMENT_ROOT() . '/../reta') . '/reta.ini'; } else { $this->retaPath = $retaPath; } if (!file_exists($this->iniFile)) { echo "<pre>"; echo "Please setup a reta.ini in the same folder as {$this->retaPath} for reporting to work:\n"; echo "[Database]\nProtocol=firebird-2.5,sqlite-3,mysql\nHostName=127.0.0.1\nPath={DBPATH}\nUser=SYSDBA\nPassword=masterkey\n"; die; } //Check if we may be on Linux - then we need to run the shell script if (PHP_OS === 'Linux') { $this->retaPath = str_replace(".exe", ".sh", $this->retaPath); $this->iniFile = "z:" . $this->iniFile; } }
new Cody(); /** * Build a phar file of the project */ Ruth::addRoute(RUTH_GET, "/build", function () { //call Phoebe with the name of the phar file, by default phoebe will build the web_root folder new Phoebe(TINA4_SESSION); }); /** * Include all the relevant paths */ Ruth::autoLoad($_TINA4_LOAD_PATHS . TINA4_INCLUDES, false); if (strpos(Ruth::getREQUEST_URI(), "/cody") !== false) { Ruth::addRoute(RUTH_GET, "/cody", function () { echo (new Cody())->codeBuilder(); }); Ruth::addRoute(RUTH_POST, "/cody/{action}", function ($action) { echo (new Cody())->codeHandler($action); }); } //We should check to see if we have a kim.db file to load routes from before parsing if (file_exists("kim.db")) { (new Kim())->loadDefines(); //these come from global settings (new Kim())->loadRoutes(); } /** * Parse all the routes, never delete this code below, you can pass a single variable through to fake the route for testing. */ Ruth::parseRoutes();
/** * */ function newSession() { Ruth::setSESSION("tessaSession", null); }
function getCodeNavigator() { $content = div(["id" => "codeNavigator", "title" => "Navigator"], $this->getFileTree(Ruth::getDOCUMENT_ROOT())); $content .= script("\$(function() { \$('#codeNavigator').dialog({position:{my: '0 0', at: 'left bottom', of: \$('#fileExplorer') }, height:400 }); } );"); return $content; }
<?php global $DEB; $DEB = new Debby("test.db", "", "", "sqlite3", "YYYY-mm-dd"); Ruth::setOBJECT("DEB", $DEB);
/** * Do Migration * * Do Migration finds the last possible migration based on what is read from the database on the constructor * It then opens the migration file, imports it into the database and tries to run each statement. * The migration files must run in sequence and Maggy will stop if she hits an error! * * DO NOT USE COMMIT STATEMENTS IN YOUR MIGRATIONS , RATHER BREAK THINGS UP INTO SMALLER LOGICAL PIECES */ function doMigration() { $dirHandle = opendir(Ruth::getREAL_PATH() . "/" . $this->migrationPath); $error = false; set_time_limit(0); echo "<pre>"; echo "STARTING Maggy ....\n"; $error = false; error_reporting(0); $fileArray = []; while (false !== ($entry = readdir($dirHandle)) && !$error) { if ($entry != "." && $entry != ".." && stripos($entry, ".sql")) { $fileParts = explode(".", $entry); $fileParts = explode(" ", $fileParts[0]); $fileArray[$fileParts[0]] = $entry; } } asort($fileArray); foreach ($fileArray as $fid => $entry) { $fileParts = explode(".", $entry); $fileParts = explode(" ", $fileParts[0]); $sqlCheck = "select * from tina4_maggy where migration_id = '{$fileParts[0]}'"; $record = $this->DEB->getRow($sqlCheck); $migrationId = $fileParts[0]; unset($fileParts[0]); $description = join(" ", $fileParts); $content = file_get_contents(Ruth::getREAL_PATH() . "/" . $this->migrationPath . "/" . $entry); $runsql = false; if (empty($record)) { echo "<span style=\"color:orange;\">RUNNING:\"{$migrationId} {$description}\" ...</span>\n"; $transId = $this->DEB->startTransaction(); $sqlInsert = "insert into tina4_maggy (migration_id, description, content, passed)\n values ('{$migrationId}', '{$description}', ?, 0)"; $this->DEB->exec($sqlInsert, $transId, $content); $this->DEB->commit($transId); $runsql = true; } else { if ($record->PASSED === "0" || $record->PASSED === "") { echo "<span style=\"color:orange;\">RETRY: \"{$migrationId} {$description}\" ... </span> \n"; $runsql = true; } else { if ($record->PASSED === "1" || $record->PASSED == 1) { echo "<span style=\"color:green;\">PASSED:\"{$migrationId} {$description}\"</span>\n"; $runsql = false; } } } if ($runsql) { $transId = $this->DEB->startTransaction(); //before exploding the content, see if it is a stored procedure, trigger or view. if (stripos($content, "create trigger") === false && stripos($content, "create procedure") === false && stripos($content, "create view") === false) { $content = explode($this->delim, $content); } else { $sql = $content; $content = []; $content[] = $sql; } $error = false; foreach ($content as $cid => $sql) { if (!empty(trim($sql))) { $success = $this->DEB->exec($sql, $transId); if (!$success) { echo "<span style=\"color:red;\">FAILED: \"{$migrationId} {$description}\"</span>\nQUERY:{$sql}\nERROR:" . $this->DEB->getError() . "\n"; $error = true; break; } else { echo "<span style=\"color:green;\">PASSED:</span> "; } echo $sql . " ...\n"; } } if ($error) { echo "<span style=\"color:red;\">FAILED: \"{$migrationId} {$description}\"</span>\nAll Transactions Rolled Back ...\n"; $this->DEB->rollbackTransaction($transId); } else { $this->DEB->commit($transId); //we need to make sure the commit resulted in no errors if ($this->DEB->getError() !== "No Error") { echo "<span style=\"color:red;\">FAILED COMMIT: \"{$migrationId} {$description}\"</span>\nERROR:" . $this->DEB->getError() . "\n"; $this->DEB->rollbackTransaction($transId); $error = true; break; } else { $transId = $this->DEB->startTransaction(); $this->DEB->exec("update tina4_maggy set passed = 1 where migration_id = '{$migrationId}'", $transId); $this->DEB->commit($transId); echo "<span style=\"color:green;\">PASSED: \"{$migrationId} {$description}\"</span>\n"; } } } } if (!$error) { echo "FINISHED!"; } error_reporting(E_ALL); echo "</pre>"; }
/** * Determines whether to show login screen etc. */ function display() { $html = $this->getPageTemplate("Tina4Stack - Kim"); //establish the session if (empty(Ruth::getSESSION("KIM"))) { Ruth::setSESSION("KIM", ["loggedin" => 0]); } $KIM = Ruth::getSESSION("KIM"); if ($KIM["loggedin"] == 0 && Ruth::getPATH() !== "/kim/login") { Ruth::redirect("/kim/login"); } if ($KIM["loggedin"] == 1) { $content = $this->getMenu(); switch (Ruth::getPATH()) { case "/kim/users": $content .= $this->getUsers(); break; case "/kim/user_types": $content .= $this->getUserTypes(); break; case "/kim/global_settings": $content .= $this->getGlobalSettings(); break; case "/kim/menus": $content .= $this->getMenuCreator(); break; case "/kim/routes": $content .= $this->getRoutes(); break; case "/kim/flush_xcache": $content .= $this->getFlushXCache(); break; case "/kim/profile": $content .= $this->getProfileUpdate(); break; case "/kim/content": $content .= $this->getContentEditor(); break; default: $content .= "Please implement the menu option " . Ruth::getPATH(); break; } } else { $content = $this->getLogin(); } $html->byId("content")->setContent($content); echo $html; }