some bug fixes to cron uploader
This commit is contained in:
parent
07cd38d34c
commit
5f0642f349
@ -30,6 +30,12 @@ class CronUploader extends Extension {
|
|||||||
*/
|
*/
|
||||||
private $root_dir = "";
|
private $root_dir = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key used to identify uploader
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $upload_key = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the cron upload page has been accessed
|
* Checks if the cron upload page has been accessed
|
||||||
* and initializes the upload.
|
* and initializes the upload.
|
||||||
@ -39,10 +45,10 @@ class CronUploader extends Extension {
|
|||||||
global $config, $user;
|
global $config, $user;
|
||||||
|
|
||||||
if ($event->page_matches ( "cron_upload" )) {
|
if ($event->page_matches ( "cron_upload" )) {
|
||||||
$key = $config->get_string ( "cron_uploader_key", "" );
|
$this->upload_key = $config->get_string ( "cron_uploader_key", "" );
|
||||||
|
|
||||||
// If the key is in the url, upload
|
// If the key is in the url, upload
|
||||||
if ($key != "" && $event->get_arg ( 0 ) == $key) {
|
if ($this->upload_key != "" && $event->get_arg ( 0 ) == $this->upload_key) {
|
||||||
// log in as admin
|
// log in as admin
|
||||||
$this->process_upload(); // Start upload
|
$this->process_upload(); // Start upload
|
||||||
}
|
}
|
||||||
@ -67,7 +73,7 @@ class CronUploader extends Extension {
|
|||||||
$uploaded_dirinfo = $this->scan_dir($uploaded_dir);
|
$uploaded_dirinfo = $this->scan_dir($uploaded_dir);
|
||||||
$failed_dirinfo = $this->scan_dir($failed_dir);
|
$failed_dirinfo = $this->scan_dir($failed_dir);
|
||||||
|
|
||||||
$cron_url = make_http(make_link("/cron_upload/" . $config->get_string('cron_uploader_key', 'invalid key' )));
|
$cron_url = make_http(make_link("/cron_upload/" . $this->upload_key));
|
||||||
$cron_cmd = "curl -f $cron_url";
|
$cron_cmd = "curl -f $cron_url";
|
||||||
$log_path = $this->root_dir . "/uploads.log";
|
$log_path = $this->root_dir . "/uploads.log";
|
||||||
|
|
||||||
@ -135,19 +141,21 @@ class CronUploader extends Extension {
|
|||||||
public function onInitExt(InitExtEvent $event) {
|
public function onInitExt(InitExtEvent $event) {
|
||||||
global $config;
|
global $config;
|
||||||
// Set default values
|
// Set default values
|
||||||
$key = $this->generate_key ();
|
if ($config->get_string("cron_uploader_key", "")) {
|
||||||
|
$this->upload_key = $this->generate_key ();
|
||||||
|
|
||||||
$config->set_default_int ( 'cron_uploader_count', 1 );
|
$config->set_default_int ( 'cron_uploader_count', 1 );
|
||||||
$config->set_default_string ( 'cron_uploader_key', $key );
|
$config->set_default_string ( 'cron_uploader_key', $this->upload_key );
|
||||||
$this->set_dir();
|
$this->set_dir();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onSetupBuilding(SetupBuildingEvent $event) {
|
public function onSetupBuilding(SetupBuildingEvent $event) {
|
||||||
global $config;
|
global $config;
|
||||||
$this->set_dir();
|
$this->set_dir();
|
||||||
|
|
||||||
$cron_url = make_http(make_link("/cron_upload/" . $config->get_string('cron_uploader_key', 'invalid key' )));
|
$cron_url = make_http(make_link("/cron_upload/" . $this->upload_key));
|
||||||
$cron_cmd = "wget $cron_url";
|
$cron_cmd = "curl -f $cron_url";
|
||||||
$documentation_link = make_http(make_link("cron_upload"));
|
$documentation_link = make_http(make_link("cron_upload"));
|
||||||
|
|
||||||
$sb = new SetupBlock ( "Cron Uploader" );
|
$sb = new SetupBlock ( "Cron Uploader" );
|
||||||
@ -194,11 +202,11 @@ class CronUploader extends Extension {
|
|||||||
|
|
||||||
// Make the directory if it doesn't exist yet
|
// Make the directory if it doesn't exist yet
|
||||||
if (!is_dir($dir . "/queue/"))
|
if (!is_dir($dir . "/queue/"))
|
||||||
mkdir ( $dir . "/queue/", 0755, true );
|
mkdir ( $dir . "/queue/", 775, true );
|
||||||
if (!is_dir($dir . "/uploaded/"))
|
if (!is_dir($dir . "/uploaded/"))
|
||||||
mkdir ( $dir . "/uploaded/", 0755, true );
|
mkdir ( $dir . "/uploaded/", 775, true );
|
||||||
if (!is_dir($dir . "/failed_to_upload/"))
|
if (!is_dir($dir . "/failed_to_upload/"))
|
||||||
mkdir ( $dir . "/failed_to_upload/", 0755, true );
|
mkdir ( $dir . "/failed_to_upload/", 0775, true );
|
||||||
|
|
||||||
$this->root_dir = $dir;
|
$this->root_dir = $dir;
|
||||||
return $dir;
|
return $dir;
|
||||||
@ -242,6 +250,7 @@ class CronUploader extends Extension {
|
|||||||
// Throw exception if there's nothing in the queue
|
// Throw exception if there's nothing in the queue
|
||||||
if (count($this->image_queue) == 0) {
|
if (count($this->image_queue) == 0) {
|
||||||
$this->add_upload_info("Your queue is empty so nothing could be uploaded.");
|
$this->add_upload_info("Your queue is empty so nothing could be uploaded.");
|
||||||
|
$this->handle_log();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,10 +298,9 @@ class CronUploader extends Extension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// move file to correct dir
|
// move file to correct dir
|
||||||
$newPath = $newDir . $filename;
|
rename($path, $newDir.$filename);
|
||||||
rename($path, $newPath);
|
|
||||||
|
|
||||||
$this->add_upload_info($info . "Image \"$filename\" moved from queue to \"$newPath\".");
|
$this->add_upload_info($info . "Image \"$filename\" moved from queue to \"$$newDir\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user