Skip to content

Commit

Permalink
Merge pull request #28 from saadbruno/issue-23
Browse files Browse the repository at this point in the history
Fix #23 - script to update all plugins now doesn't halt on fail
  • Loading branch information
saadbruno authored Sep 12, 2022
2 parents 346522c + 19056f3 commit 689cbdc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
15 changes: 5 additions & 10 deletions code/bin/update_plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
exit;
}

// changes directory to current script, so the rel patchs work, independently of the user's current directory
// changes directory to current script, so the relative paths work, independently of the user's current directory
chdir(dirname(__FILE__));

require_once "../lib/functions.php";
Expand All @@ -17,27 +17,22 @@
require_once "../lib/db/submit.php";


if ($argv[1]) {
if ($argv[1]) { // if the user provided a specific github URL to update

$githubUrl = $argv[1];
savePlugin($githubUrl, true);

} else {
} else { // else we run for all plugins

// build the query
$query = "SELECT `plugins`.`id`,`plugins`.`name`,`plugins`.`owner`,`users`.`username` ";
$query .= "FROM `plugins` ";
$query .= "LEFT JOIN `users` ";
$query .= "ON `plugins`.`owner` = `users`.`id`;";
$query = "SELECT `plugins`.`url` FROM `plugins`";

// get plugins
$stmt_plugins = $pdo->prepare($query);
$stmt_plugins->execute();
$plugins_array = $stmt_plugins->fetchAll();

foreach ($plugins_array as $row_plugins) {
// builds the github URL
$githubUrl = "https://github.com/" . $row_plugins['username'] . "/" . $row_plugins['name'];
savePlugin($githubUrl, true);
savePlugin($row_plugins['url'], true);
}
}
3 changes: 1 addition & 2 deletions code/features/home/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
// if a plugin was submitted
if (isset($_POST['githubUrl'])) {
$githubUrl = filter_input(INPUT_POST, 'githubUrl', FILTER_SANITIZE_URL);
savePlugin($githubUrl);
die();
die(savePlugin($githubUrl));
}

$nav['active'] = 'home';
Expand Down
21 changes: 16 additions & 5 deletions code/lib/db/submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function savePlugin($githubUrl, $skipDate = false)
$result = array();
$result['status'] = 'error';
$result['message'] = 'URL is not valid';
die(json_encode($result));
return json_encode($result);
}

// puts array into variables so we can use them below:
Expand Down Expand Up @@ -115,6 +115,16 @@ function savePlugin($githubUrl, $skipDate = false)

// debug($result, 'Raw GitHub API result');

// If Git|Hub returns an error, we return before trying to mess with the database
if (isset($result['errors'])) {
header('Content-Type: application/json; charset=UTF-8');
$result = array();
$result['status'] = 'error';
$result['message'] = 'GitHub link not found. Are you sure the URL is correct and the repo is public?';

return json_encode($result);
}

// converts the timestamp
$updatedAt = date("U", strtotime($result['data']['repository']['updatedAt']));
$submittedAt = time();
Expand Down Expand Up @@ -223,7 +233,7 @@ function savePlugin($githubUrl, $skipDate = false)
$result['message'] .= $e;
}

die(json_encode($result));
return json_encode($result);
}


Expand Down Expand Up @@ -252,7 +262,7 @@ function savePlugin($githubUrl, $skipDate = false)
$result = array();
$result['status'] = 'error';
$result['message'] = 'Error when adding user';
die(json_encode($result));
return json_encode($result);
}


Expand All @@ -278,7 +288,7 @@ function savePlugin($githubUrl, $skipDate = false)
$result = array();
$result['status'] = 'error';
$result['message'] = 'Error when adding tags';
die(json_encode($result));
return json_encode($result);
}
}

Expand All @@ -292,9 +302,10 @@ function savePlugin($githubUrl, $skipDate = false)
$result['message'] = 'success';
$result['redirect'] = $redirect;
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($result, true);

// debugging code
debug($url, "URL Debugging");
debug( json_encode($result), "RESULT");

return json_encode($result, true);
}

0 comments on commit 689cbdc

Please sign in to comment.