<?php include "../patches.php"; $patch = new Patch(18); if (!$patch->exists()) { $createSql = "CREATE TABLE IF NOT EXISTS `webcam_images` (\n\t\t\t `timestamp` datetime NOT NULL,\n\t\t\t `image_id` bigint(11) unsigned NOT NULL,\n\t\t\t `user_id` int(11) unsigned NOT NULL,\n\t\t\t `bot_id` int(11) unsigned NULL,\n\t\t\t `job_id` int(11) unsigned NULL,\n\t\t\t PRIMARY KEY (`timestamp`, `image_id`),\n\t\t\t FOREIGN KEY (`image_id`) REFERENCES s3_files(`id`) ON DELETE CASCADE,\n\t\t\t FOREIGN KEY (`user_id`) REFERENCES users(`id`) ON DELETE CASCADE,\n\t\t\t FOREIGN KEY (`bot_id`) REFERENCES bots(`id`) ON DELETE CASCADE,\n\t\t\t FOREIGN KEY (`job_id`) REFERENCES jobs(`id`) ON DELETE CASCADE\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; db()->execute($createSql); $failCount = 0; $rowSql = "SELECT id from jobs where webcam_images!=''"; $jobsCollection = new Collection($rowSql); $jobsCollection->bindType('id', 'Job'); $jobs = $jobsCollection->getAll(); $total = $jobsCollection->count(); $count = 0; $patch->progress(0); // Get the current webcam images in an array, so we can quickly skip those. $pdoStatement = db()->query("SELECT image_id from webcam_images"); $existingImages = array(); foreach ($pdoStatement->fetchAll(PDO::FETCH_ASSOC) as $row) { $existingImages[$row['image_id']] = true; } foreach ($jobs as $row) { /** @var Job $job */ $job = $row['Job']; $images_json = $job->get('webcam_images'); if ($job->isHydrated() && $images_json != "") { $images = json_decode($images_json, true); $rowData = array(); foreach ($images as $timestamp => $image_id) { if (!array_key_exists($image_id, $existingImages)) { $file = Storage::get($image_id);