Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve installation script and various small fixes #161

Merged
merged 24 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9d1cc2e
Improve installation script
gartens Nov 21, 2023
1431549
Remove mercurial option from installer
gartens Nov 22, 2023
2468f7c
Disable FTP upload for local clients by default
gartens Nov 22, 2023
2a518b1
Avoid passing null to method_exists
gartens Dec 5, 2023
19d793a
Avoid warnings about implicit conversions from float to integer
gartens Dec 5, 2023
0a08735
Display a 404 page for non-existent controllers/actions
gartens Dec 5, 2023
22976ae
Replace blurry "plus" PNG with a crisp SVG
gartens Dec 5, 2023
d6c715a
Replace multiple instances of file_exists + file_get_contents with he…
gartens Dec 5, 2023
8ae13d0
Use correct variable in exception message
gartens Dec 5, 2023
ae017b6
Exit early when the class name does conform to our expectations
gartens Dec 5, 2023
6ba2306
Fix typo
gartens Dec 5, 2023
a50c13b
Use O_EXCL to prevent races when creating the lock file
gartens Dec 5, 2023
352892a
Return early when $result is null
gartens Dec 5, 2023
9751aeb
Get current branch directly from Git
gartens Dec 5, 2023
9b09df5
Avoid indexing a null value
gartens Dec 5, 2023
7d6e3ad
Use user id for membership check
gartens Dec 5, 2023
427b698
Avoid deprecation warning
gartens Dec 5, 2023
1c8f803
Make path checking in .htaccess files a bit stricter
gartens Dec 5, 2023
5de8af6
Read System::RESULTS again after convertResults
gartens Dec 5, 2023
3702225
Further improvements to .htaccess and default route
gartens Dec 7, 2023
a06447a
Redirect user to index.php when installation was successful
gartens Dec 7, 2023
3e34e4c
Remove a leftover comment and add back a sleep call
gartens Dec 13, 2023
977fc6a
Readd dies
vogti Apr 24, 2024
68f1ca5
Adjust dies
vogti Apr 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .htaccess
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC,OR]
RewriteCond %{HTTP_HOST} ^
RewriteCond %{REQUEST_URI} !webroot/
RewriteCond %{REQUEST_URI} !^/webroot/
RewriteRule (.*) /webroot/$1 [L]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Systems evaluations are an important part of development and empirical research
* PHP 5.6 or higher
* Apache2 with active mod_rewrite
* Apache config `AllowOverride All` needs to be set
* Git


### Installation procedure
Expand Down
16 changes: 5 additions & 11 deletions api/v1/job.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function get() {
}
$filters = [];
if ($this->get['supports'] == 'demoall') { // demo mode to match all systems
// we acceppt all systems now
// we accept all systems now
} else {
$supports = Systems_Library::getArrayFromString($this->get['supports']);
$filters[] = new ContainFilter(Job::SYSTEM_ID, $supports);
Expand Down Expand Up @@ -103,22 +103,16 @@ public function get() {

if (isset($this->get['withLog']) && $this->get['withLog'] == true) {
$path = UPLOADED_DATA_PATH . '/log/' . $job->getId() . '.log';
if (file_exists($path)) {
// read log from file
$log = file_get_contents($path);
if ($log === false) {
$data->log = "";
} else {
$data->log = $log;
}
} else {
$log = Util::readFileContents($path);
if ($log === false) {
$data->log = "";
} else {
$data->log = $log;
}
}
$this->add($data);
}


public $post_access = Auth_Library::A_PUBLIC;

/**
Expand Down
6 changes: 5 additions & 1 deletion controllers/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,11 @@ public function system() {
$this->view->assign('system', $system);
$systemLib = new System($system->getId());
$results = json_decode($systemLib->getResultsAll(), true);
$this->view->assign('results', $results['elements']);
if ($results === null) {
$this->view->assign('results', []);
} else {
$this->view->assign('results', $results['elements']);
}
$this->view->assign('identifier', $systemLib->getIdentifier());
$users = Factory::getUserFactory()->filter([]);
$this->view->assign('users', $users);
Expand Down
2 changes: 1 addition & 1 deletion controllers/project.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,4 @@ public function detail() {
throw new Exception("No project id provided!");
}
}
}
}
5 changes: 4 additions & 1 deletion core/autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ function loader($className) {
$folder = '/core/';
} else {
//parse out filename where class should be located
if (!str_contains($className, '_')) {
die("Invalid class name for autoload");
}
list($filename, $suffix) = preg_split('/_/', $className);

//select the folder where class should be located based on suffix
Expand Down Expand Up @@ -86,4 +89,4 @@ function loader($className) {
}
}

spl_autoload_register("loader");
spl_autoload_register("loader");
5 changes: 3 additions & 2 deletions core/element.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ class Element {
*/
public function __construct($path) {
$this->path = $path . "/";
if (!file_exists($this->path . "config.json")) {
$file = Util::readFileContents($this->path . "config.json");
if ($file === false) {
throw new Exception("No config available for element '$this->path'!");
}
$this->config = json_decode(file_get_contents($this->path . "config.json"), true);
$this->config = json_decode($file, true);
}

public function isValid() {
Expand Down
5 changes: 3 additions & 2 deletions core/plot.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ class Plot {
*/
public function __construct($path) {
$this->path = $path . "/";
if (!file_exists($this->path . "config.json")) {
$file = Util::readFileContents($this->path . "config.json");
if ($file === false) {
throw new Exception("No config available for plot '$this->path'!");
}
$this->config = json_decode(file_get_contents($this->path . "config.json"), true);
$this->config = json_decode($file, true);
}

public function isValid() {
Expand Down
6 changes: 3 additions & 3 deletions core/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
$log->debug('query string: ' . $request);

// if $request is empty (user called www.domain.tld) show home
if ($request == '') {
if ($request === '' or $request === '/') {
$page = DEFAULT_CONTROLLER;
$action = DEFAULT_ACTION;
$getVars = [];
Expand Down Expand Up @@ -138,11 +138,11 @@
}

// check if function exists
if (!method_exists($controller, $action)) {
if ($action === null or !method_exists($controller, $action)) {
// function does not exist!
$found = false;
$log->debug('=> class found, but action does not exist: ' . $action);
die('=> class found, but action does not exist: ' . $action);
die('class found, but action does not exist: ' . $action);
}
$log->debug('controller found and instantiated: ' . $class);
} else {
Expand Down
44 changes: 25 additions & 19 deletions core/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ public function __construct($systemId) {
throw new Exception("Failed to load system with ID $systemId!");
}
$this->path = SERVER_ROOT . "/webroot/systems/" . $this->model->getId() . "/";
if (!file_exists($this->path . "config.json")) {
$content = Util::readFileContents($this->path . System::CONFIG);
if ($content === false) {
throw new Exception("Failed to load config for system with ID " . $this->model->getId());
}
$this->config = json_decode(file_get_contents($this->path . System::CONFIG), true);
$this->config = json_decode($content, true);
}

public function getName() {
Expand Down Expand Up @@ -106,18 +107,19 @@ public function getViews() {
}

public function getParameters() {
if (!file_exists($this->path . System::PARAMETERS)) {
$contents = Util::readFileContents($this->path . System::PARAMETERS);
if ($contents === false) {
return "{}";
}
return file_get_contents($this->path . System::PARAMETERS);
return $contents;
}

public function getResultsAll($resultId = "") {
if (!file_exists($this->path . System::RESULTS)) {
$data = Util::readFileContents($this->path . System::RESULTS);
if ($data === false) {
$this->convertResults();
$data = Util::readFileContents($this->path . System::RESULTS);
}

$data = file_get_contents($this->path . System::RESULTS);
if ($resultId != "") {
$json = json_decode($data, true);
if (!isset($json["elements"][$resultId])) {
Expand All @@ -130,32 +132,36 @@ public function getResultsAll($resultId = "") {
}

private function convertResults() {
if (!file_exists($this->path . System::RESULTS_JOB)) {
$dataJob = Util::readFileContents($this->path . System::RESULTS_JOB);
$dataAll = Util::readFileContents($this->path . System::RESULTS_ALL);
if ($dataJob === false) {
$dataJob = "{}";
} else {
$dataJob = file_get_contents($this->path . System::RESULTS_JOB);
}
if (!file_exists($this->path . System::RESULTS_ALL)) {
if ($dataAll === false) {
$dataAll = "{}";
} else {
$dataAll = file_get_contents($this->path . System::RESULTS_ALL);
}
$jsonJob = json_decode($dataJob, true);
$jsonAll = json_decode($dataAll, true);

$json = ["version" => "1.0", "elements" => ["system-1" => ["job" => $jsonJob, "all" => $jsonAll, "name" => "Default"]]];
$this->setResultsAll(json_encode($json));
unlink($this->path . System::RESULTS_ALL);
unlink($this->path . System::RESULTS_JOB);
sleep(1);
if (file_exists($this->path . System::RESULTS_ALL)) {
unlink($this->path . System::RESULTS_ALL);
}
if (file_exists($this->path . System::RESULTS_JOB)) {
unlink($this->path . System::RESULTS_JOB);
}
sleep(1);
}

public function getResultsJob($resultId = "") {
if (!file_exists($this->path . System::RESULTS)) {
$data = file_get_contents($this->path . System::RESULTS);

if ($data === false) {
$this->convertResults();
$data = file_get_contents($this->path . System::RESULTS);
}

$data = file_get_contents($this->path . System::RESULTS);
if ($resultId != "") {
$json = json_decode($data, true);
if (!isset($json["elements"][$resultId])) {
Expand Down Expand Up @@ -219,4 +225,4 @@ public function deleteResults($resultId) {
file_put_contents($this->path . System::RESULTS, json_encode($data));
VCS_Library::commit($this->path, "Deleted results ID: $resultId");
}
}
}
25 changes: 12 additions & 13 deletions core/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static function mergeJobs($jobs, $parameter) {
* @throws Exception
*/
public static function scanForPlots($path) {
if (!file_exists($path) || !is_dir($path)) {
if (!is_dir($path)) {
return [];
}
$dir = scandir($path);
Expand Down Expand Up @@ -245,6 +245,16 @@ public static function recursiveCopy($src, $dst) {
closedir($dir);
}

public static function readFileContents(string $file): string|false {
// There is still a window where the file can be deleted, and
// file_get_contents prints a warning to the page. But when there
// is a way without that, only this helper needs to be changed.
if (file_exists($file)) {
return file_get_contents($file);
}
return false;
}

public static function getObjectFromPhasesBitMask($bitMask, $obj = null) {
if ($obj == null) {
$obj = new stdClass();
Expand Down Expand Up @@ -456,15 +466,4 @@ public static function getNextIdForSystemResults($systemId) {
return $newId;
}

public static function updateSumsAndCounts($array, &$sums, &$counts) {
foreach ($array as $index => $value) {
if (isset($sums[$index])) {
$sums[$index] += $value;
$counts[$index] += 1;
} else {
$sums[$index] = $value;
$counts[$index] = 1;
}
}
}
}
}
Loading