Files
itflow/cron/ticket_pictures.php

45 lines
1.9 KiB
PHP

<?php
// Set working directory to the directory this cron script lives at.
chdir(dirname(__FILE__));
// Ensure we're running from command line
if (php_sapi_name() !== 'cli') {
die("This script must be run from the command line.\n");
}
// Prevent overlapping runs of this script
$cron_lock_script = __FILE__;
require_once "includes/cron_lock.php";
require_once "../config.php";
require_once "../includes/inc_set_timezone.php";
require_once "../functions.php";
/*
* ITFlow - Ticket pictures
*
* Runs every minute. Moves pictures kept inside tickets' details and replies as data into each
* ticket's files - those from before the 4.2.4 update, and any kept that way since by something
* that doesn't make them files, a recurring ticket's or a template's - for up to 25 seconds a run,
* carrying on from where the last run got to (ticketPicturesSweep(), functions/ticket_pictures.php).
* Once through every ticket it only looks at new ones.
*/
// Read the master switch here rather than trusting a global - see the cron rules in CONTRIBUTING.md
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT config_enable_cron FROM settings WHERE company_id = 1"));
if (intval($row['config_enable_cron'] ?? 0) === 0) {
cronJobStop("Cron: is not enabled -- Quitting..");
}
$swept = ticketPicturesSweep(25);
if ($swept === null) {
cronJobStop("The database needs updating first");
}
if ($swept['texts']) {
echo "Ticket pictures: {$swept['moved']} moved into files, in {$swept['texts']} tickets and replies" . ($swept['behind'] ? ' - more next run' : '') . "\n";
}
// Pictures it couldn't save stay as they were, in the text - said once a run, for whoever looks into why
if ($swept['failed']) {
logApp("Cron-Ticket-Pictures", "warning", "{$swept['failed']} picture(s) in tickets couldn't be saved as files and were left in the text - check that uploads/tickets is writable by the user cron runs as.");
}