Revert "Merge tag 'v2.10.6'"

This reverts commit 122ea4ab9e, reversing
changes made to c54a11e250.
This commit is contained in:
2024-02-16 23:06:09 -06:00
parent 122ea4ab9e
commit 6c08ee9675
521 changed files with 12363 additions and 14503 deletions

View File

@@ -21,7 +21,7 @@ class CronUploader extends Extension
private static bool $IMPORT_RUNNING = false;
public function onInitUserConfig(InitUserConfigEvent $event): void
public function onInitUserConfig(InitUserConfigEvent $event)
{
$event->user_config->set_default_string(
CronUploaderConfig::DIR,
@@ -32,7 +32,7 @@ class CronUploader extends Extension
$event->user_config->set_default_int(CronUploaderConfig::LOG_LEVEL, SCORE_LOG_INFO);
}
public function onUserOptionsBuilding(UserOptionsBuildingEvent $event): void
public function onUserOptionsBuilding(UserOptionsBuildingEvent $event)
{
if ($event->user->can(Permissions::CRON_ADMIN)) {
$documentation_link = make_http(make_link("cron_upload"));
@@ -55,9 +55,9 @@ class CronUploader extends Extension
}
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event): void
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event)
{
if ($event->parent == "system") {
if ($event->parent=="system") {
$event->add_nav_link("cron_docs", new Link('cron_upload'), "Cron Upload");
}
}
@@ -66,12 +66,12 @@ class CronUploader extends Extension
* Checks if the cron upload page has been accessed
* and initializes the upload.
*/
public function onPageRequest(PageRequestEvent $event): void
public function onPageRequest(PageRequestEvent $event)
{
global $user;
if ($event->page_matches("cron_upload")) {
if ($event->count_args() == 1 && $event->get_arg(0) == "run") {
if ($event->count_args() == 1 && $event->get_arg(0) =="run") {
$this->process_upload(); // Start upload
} elseif ($user->can(Permissions::CRON_RUN)) {
$this->display_documentation();
@@ -79,7 +79,7 @@ class CronUploader extends Extension
}
}
public function onAdminBuilding(AdminBuildingEvent $event): void
public function onAdminBuilding(AdminBuildingEvent $event)
{
$failed_dir = $this->get_failed_dir();
$results = get_dir_contents($failed_dir);
@@ -95,7 +95,7 @@ class CronUploader extends Extension
$this->theme->display_form($failed_dirs);
}
public function onAdminAction(AdminActionEvent $event): void
public function onAdminAction(AdminActionEvent $event)
{
$action = $event->action;
switch ($action) {
@@ -120,14 +120,14 @@ class CronUploader extends Extension
}
}
public function onLog(LogEvent $event): void
public function onLog(LogEvent $event)
{
global $user_config;
if (self::$IMPORT_RUNNING) {
$all = $user_config->get_bool(CronUploaderConfig::INCLUDE_ALL_LOGS);
if ($event->priority >= $user_config->get_int(CronUploaderConfig::LOG_LEVEL) &&
($event->section == self::NAME || $all)) {
($event->section==self::NAME || $all)) {
$output = "[" . date('Y-m-d H:i:s') . "] " . ($all ? '[' . $event->section . '] ' : '') . "[" . LOGGING_LEVEL_NAMES[$event->priority] . "] " . $event->message;
echo $output . "\r\n";
@@ -139,7 +139,7 @@ class CronUploader extends Extension
}
}
private function restage_folder(string $folder): void
private function restage_folder(string $folder)
{
global $page;
if (empty($folder)) {
@@ -157,7 +157,7 @@ class CronUploader extends Extension
$results = get_files_recursively($stage_dir);
if (count($results) == 0) {
if (remove_empty_dirs($stage_dir) === false) {
if (remove_empty_dirs($stage_dir)===false) {
$page->flash("Nothing to stage from $folder, cannot remove folder");
} else {
$page->flash("Nothing to stage from $folder, removing folder");
@@ -182,21 +182,21 @@ class CronUploader extends Extension
mkdir($dir, 0775, true);
}
if (rename($result, $new_path) === false) {
if (rename($result, $new_path)===false) {
$page->flash("Could not move file: " .$result);
$success = false;
}
}
if ($success === true) {
if ($success===true) {
$page->flash("Re-staged $folder to queue");
if (remove_empty_dirs($stage_dir) === false) {
if (remove_empty_dirs($stage_dir)===false) {
$page->flash("Could not remove $folder");
}
}
}
private function clear_folder(string $folder): void
private function clear_folder($folder)
{
global $page, $user_config;
$path = join_path($user_config->get_string(CronUploaderConfig::DIR), $folder);
@@ -235,7 +235,7 @@ class CronUploader extends Extension
$running = false;
$lockfile = false_throws(fopen($this->get_lock_file(), "w"));
$lockfile = fopen($this->get_lock_file(), "w");
try {
if (!flock($lockfile, LOCK_EX | LOCK_NB)) {
$running = true;
@@ -325,7 +325,7 @@ class CronUploader extends Extension
{
global $database, $user, $user_config, $config, $_shm_load_start;
$max_time = intval(ini_get('max_execution_time')) * .8;
$max_time = intval(ini_get('max_execution_time'))*.8;
$this->set_headers();
@@ -343,7 +343,7 @@ class CronUploader extends Extension
throw new SCoreException("User does not have permission to run cron upload");
}
$lockfile = false_throws(fopen($this->get_lock_file(), "w"));
$lockfile = fopen($this->get_lock_file(), "w");
if (!flock($lockfile, LOCK_EX | LOCK_NB)) {
throw new SCoreException("Cron upload process is already running");
}
@@ -365,25 +365,34 @@ class CronUploader extends Extension
// Upload the file(s)
foreach ($image_queue as $img) {
$execution_time = ftime() - $_shm_load_start;
if ($execution_time > $max_time) {
if ($execution_time>$max_time) {
break;
} else {
$remaining = $max_time - $execution_time;
$this->log_message(SCORE_LOG_DEBUG, "Max run time remaining: $remaining");
}
try {
$result = $database->with_savepoint(function () use ($img, $output_subdir) {
$this->log_message(SCORE_LOG_INFO, "Adding file: {$img[0]} - tags: {$img[2]}");
$result = $this->add_image($img[0], $img[1], $img[2]);
$this->move_uploaded($img[0], $img[1], $output_subdir, false);
return $result;
});
$database->begin_transaction();
$this->log_message(SCORE_LOG_INFO, "Adding file: {$img[0]} - tags: {$img[2]}");
$result = $this->add_image($img[0], $img[1], $img[2]);
if ($database->is_transaction_open()) {
$database->commit();
}
$this->move_uploaded($img[0], $img[1], $output_subdir, false);
if ($result->merged) {
$merged++;
} else {
$added++;
}
} catch (\Exception $e) {
try {
if ($database->is_transaction_open()) {
$database->rollback();
}
} catch (\Exception $e) {
// rollback failed, let's just log things and die
}
$failed++;
$this->log_message(SCORE_LOG_ERROR, "(" . gettype($e) . ") " . $e->getMessage());
$this->log_message(SCORE_LOG_ERROR, $e->getTraceAsString());
@@ -396,7 +405,7 @@ class CronUploader extends Extension
}
// Throw exception if there's nothing in the queue
if ($merged + $failed + $added === 0) {
if ($merged+$failed+$added === 0) {
$this->log_message(SCORE_LOG_WARNING, "Your queue is empty so nothing could be uploaded.");
return false;
}
@@ -414,19 +423,19 @@ class CronUploader extends Extension
}
}
private function move_uploaded(string $path, string $filename, string $output_subdir, bool $corrupt = false): void
private function move_uploaded(string $path, string $filename, string $output_subdir, bool $corrupt = false)
{
global $user_config;
$rootDir = $user_config->get_string(CronUploaderConfig::DIR);
$rootLength = strlen($rootDir);
if ($rootDir[$rootLength - 1] == "/" || $rootDir[$rootLength - 1] == "\\") {
if ($rootDir[$rootLength-1]=="/"||$rootDir[$rootLength-1]=="\\") {
$rootLength--;
}
$relativeDir = dirname(substr($path, $rootLength + 7));
if ($relativeDir == ".") {
if ($relativeDir==".") {
$relativeDir = "";
}
@@ -454,24 +463,18 @@ class CronUploader extends Extension
/**
* Generate the necessary DataUploadEvent for a given image and tags.
*
* @param string[] $tags
*/
private function add_image(string $tmpname, string $filename, array $tags): DataUploadEvent
private function add_image(string $tmpname, string $filename, string $tags): DataUploadEvent
{
$event = send_event(new DataUploadEvent($tmpname, [
'filename' => pathinfo($filename, PATHINFO_BASENAME),
'tags' => $tags,
'source' => null,
]));
$event = add_image($tmpname, $filename, $tags, null);
// Generate info message
if (count($event->images) == 0) {
if ($event->image_id == -1) {
throw new UploadException("File type not recognised (".$event->mime."). Filename: {$filename}");
} elseif ($event->merged === true) {
$infomsg = "Post merged. ID: {$event->images[0]->id} - Filename: {$filename}";
$infomsg = "Post merged. ID: {$event->image_id} - Filename: {$filename}";
} else {
$infomsg = "Post uploaded. ID: {$event->images[0]->id} - Filename: {$filename}";
$infomsg = "Post uploaded. ID: {$event->image_id} - Filename: {$filename}";
}
$this->log_message(SCORE_LOG_INFO, $infomsg);
@@ -479,7 +482,7 @@ class CronUploader extends Extension
}
private const PARTIAL_DOWNLOAD_EXTENSIONS = ['crdownload','part'];
private const SKIPPABLE_FILES = ['.ds_store', 'thumbs.db', 'desktop.ini', '.listing'];
private const SKIPPABLE_FILES = ['.ds_store','thumbs.db'];
private function is_skippable_file(string $path): bool
{