Added lock file usage to cron uploader to prevent concurrent runs.
Changed extension manager to allow author to be a comma-separated list.
This commit is contained in:
parent
e940d87c22
commit
0202597f88
@ -1,12 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Name: Cron Uploader
|
* Name: Cron Uploader
|
||||||
* Author: YaoiFox <admin@yaoifox.com>
|
* Authors: YaoiFox <admin@yaoifox.com>, Matthew Barbour <matthew@darkholme.net>
|
||||||
* Link: http://www.yaoifox.com/
|
* Link: http://www.yaoifox.com/
|
||||||
* License: GPLv2
|
* License: GPLv2
|
||||||
* Description: Uploads images automatically using Cron Jobs
|
* Description: Uploads images automatically using Cron Jobs
|
||||||
* Documentation: Installation guide: activate this extension and navigate to www.yoursite.com/cron_upload
|
* Documentation: Installation guide: activate this extension and navigate to www.yoursite.com/cron_upload
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class CronUploader extends Extension
|
class CronUploader extends Extension
|
||||||
{
|
{
|
||||||
// TODO: Checkbox option to only allow localhost + a list of additional IP adresses that can be set in /cron_upload
|
// TODO: Checkbox option to only allow localhost + a list of additional IP adresses that can be set in /cron_upload
|
||||||
@ -51,7 +53,18 @@ class CronUploader extends Extension
|
|||||||
// If the key is in the url, upload
|
// If the key is in the url, upload
|
||||||
if ($this->upload_key != "" && $event->get_arg(0) == $this->upload_key) {
|
if ($this->upload_key != "" && $event->get_arg(0) == $this->upload_key) {
|
||||||
// log in as admin
|
// log in as admin
|
||||||
|
$this->set_dir();
|
||||||
|
|
||||||
|
$lockfile = fopen($this->root_dir . "/.lock", "w");
|
||||||
|
try {
|
||||||
|
if (!flock($lockfile, LOCK_EX | LOCK_NB)) {
|
||||||
|
throw new Exception("Cron upload process is already running");
|
||||||
|
}
|
||||||
$this->process_upload(); // Start upload
|
$this->process_upload(); // Start upload
|
||||||
|
} finally {
|
||||||
|
flock($lockfile, LOCK_UN);
|
||||||
|
fclose($lockfile);
|
||||||
|
}
|
||||||
} elseif ($user->is_admin()) {
|
} elseif ($user->is_admin()) {
|
||||||
$this->set_dir();
|
$this->set_dir();
|
||||||
$this->display_documentation();
|
$this->display_documentation();
|
||||||
@ -131,6 +144,8 @@ class CronUploader extends Extension
|
|||||||
<br />This link can be found under 'Cron Command' in the board config, just remove the 'wget ' part and only the url remains.
|
<br />This link can be found under 'Cron Command' in the board config, just remove the 'wget ' part and only the url remains.
|
||||||
<br />(<b>$cron_url</b>)";
|
<br />(<b>$cron_url</b>)";
|
||||||
|
|
||||||
|
$page->set_title("Cron Uploader");
|
||||||
|
$page->set_heading("Cron Uploader");
|
||||||
|
|
||||||
$block = new Block("Cron Uploader", $info_html, "main", 10);
|
$block = new Block("Cron Uploader", $info_html, "main", 10);
|
||||||
$block_install = new Block("Installation Guide", $install_html, "main", 20);
|
$block_install = new Block("Installation Guide", $install_html, "main", 20);
|
||||||
@ -246,10 +261,10 @@ class CronUploader extends Extension
|
|||||||
{
|
{
|
||||||
global $config, $database;
|
global $config, $database;
|
||||||
|
|
||||||
set_time_limit(0);
|
//set_time_limit(0);
|
||||||
|
|
||||||
|
|
||||||
$output_subdir = date('Ymd-His', time()) . "/";
|
$output_subdir = date('Ymd-His', time()) . "/";
|
||||||
$this->set_dir();
|
|
||||||
$this->generate_image_queue();
|
$this->generate_image_queue();
|
||||||
|
|
||||||
// Gets amount of imgs to upload
|
// Gets amount of imgs to upload
|
||||||
@ -310,11 +325,11 @@ class CronUploader extends Extension
|
|||||||
$msgNumber = $this->add_upload_info("Items failed: $failed");
|
$msgNumber = $this->add_upload_info("Items failed: $failed");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Display & save upload log
|
// Display & save upload log
|
||||||
$this->handle_log();
|
$this->handle_log();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function move_uploaded($path, $filename, $output_subdir, $corrupt = false)
|
private function move_uploaded($path, $filename, $output_subdir, $corrupt = false)
|
||||||
|
@ -22,8 +22,7 @@ class ExtensionInfo
|
|||||||
public $ext_name;
|
public $ext_name;
|
||||||
public $name;
|
public $name;
|
||||||
public $link;
|
public $link;
|
||||||
public $author;
|
public $authors;
|
||||||
public $email;
|
|
||||||
public $description;
|
public $description;
|
||||||
public $documentation;
|
public $documentation;
|
||||||
public $version;
|
public $version;
|
||||||
@ -39,6 +38,7 @@ class ExtensionInfo
|
|||||||
$this->ext_name = $matches[1];
|
$this->ext_name = $matches[1];
|
||||||
$this->name = $this->ext_name;
|
$this->name = $this->ext_name;
|
||||||
$this->enabled = $this->is_enabled($this->ext_name);
|
$this->enabled = $this->is_enabled($this->ext_name);
|
||||||
|
$this->authors = [];
|
||||||
|
|
||||||
for ($i = 0; $i < $number_of_lines; $i++) {
|
for ($i = 0; $i < $number_of_lines; $i++) {
|
||||||
$line = $lines[$i];
|
$line = $lines[$i];
|
||||||
@ -53,11 +53,17 @@ class ExtensionInfo
|
|||||||
}
|
}
|
||||||
} elseif (preg_match("/Version: (.*)/", $line, $matches)) {
|
} elseif (preg_match("/Version: (.*)/", $line, $matches)) {
|
||||||
$this->version = $matches[1];
|
$this->version = $matches[1];
|
||||||
} elseif (preg_match("/Author: (.*) [<\(](.*@.*)[>\)]/", $line, $matches)) {
|
} elseif (preg_match("/Authors?: (.*)/", $line, $matches)) {
|
||||||
$this->author = $matches[1];
|
$author_list = explode(',', $matches[1]);
|
||||||
$this->email = $matches[2];
|
foreach ($author_list as $author) {
|
||||||
} elseif (preg_match("/Author: (.*)/", $line, $matches)) {
|
if (preg_match("/(.*) [<\(](.*@.*)[>\)]/", $author, $matches)) {
|
||||||
$this->author = $matches[1];
|
$this->authors[] = new ExtensionAuthor($matches[1], $matches[2]);
|
||||||
|
} else {
|
||||||
|
$this->authors[] = new ExtensionAuthor($author, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} elseif (preg_match("/(.*)Description: ?(.*)/", $line, $matches)) {
|
} elseif (preg_match("/(.*)Description: ?(.*)/", $line, $matches)) {
|
||||||
$this->description = $matches[2];
|
$this->description = $matches[2];
|
||||||
$start = $matches[1] . " ";
|
$start = $matches[1] . " ";
|
||||||
@ -96,6 +102,18 @@ class ExtensionInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ExtensionAuthor
|
||||||
|
{
|
||||||
|
public $name;
|
||||||
|
public $email;
|
||||||
|
|
||||||
|
public function __construct(string $name, string $email)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
$this->email = $email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ExtManager extends Extension
|
class ExtManager extends Extension
|
||||||
{
|
{
|
||||||
public function onPageRequest(PageRequestEvent $event)
|
public function onPageRequest(PageRequestEvent $event)
|
||||||
|
@ -116,13 +116,22 @@ class ExtManagerTheme extends Themelet
|
|||||||
public function display_doc(Page $page, ExtensionInfo $info)
|
public function display_doc(Page $page, ExtensionInfo $info)
|
||||||
{
|
{
|
||||||
$author = "";
|
$author = "";
|
||||||
if ($info->author) {
|
if (count($info->authors) > 0) {
|
||||||
if ($info->email) {
|
$author = "<br /><b>Author";
|
||||||
$author = "<br><b>Author:</b> <a href=\"mailto:".html_escape($info->email)."\">".html_escape($info->author)."</a>";
|
if (count($info->authors) > 1) {
|
||||||
|
$author .= "s";
|
||||||
|
}
|
||||||
|
$author .= ":</b>";
|
||||||
|
foreach ($info->authors as $auth) {
|
||||||
|
if (!empty($auth->email)) {
|
||||||
|
$author .= "<a href=\"mailto:" . html_escape($auth->email) . "\">" . html_escape($auth->name) . "</a>";
|
||||||
} else {
|
} else {
|
||||||
$author = "<br><b>Author:</b> ".html_escape($info->author);
|
$author .= html_escape($auth->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$version = ($info->version) ? "<br><b>Version:</b> " . html_escape($info->version) : "";
|
$version = ($info->version) ? "<br><b>Version:</b> " . html_escape($info->version) : "";
|
||||||
$link = ($info->link) ? "<br><b>Home Page:</b> <a href=\"" . html_escape($info->link) . "\">Link</a>" : "";
|
$link = ($info->link) ? "<br><b>Home Page:</b> <a href=\"" . html_escape($info->link) . "\">Link</a>" : "";
|
||||||
$doc = $info->documentation;
|
$doc = $info->documentation;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user