public function getActiveBots() { $sql = "SELECT id, queue_id, job_id\n\t\t\t\tFROM bots\n\t\t\t\tWHERE oauth_token_id = ?\n\t\t\t\tAND status != 'retired'\n\t\t\t\tORDER BY name"; $bots = new Collection($sql, array($this->id)); $bots->bindType('id', 'Bot'); $bots->bindType('queue_id', 'Queue'); $bots->bindType('job_id', 'Job'); return $bots; }
public function pretty() { $this->assertAdmin(); $this->setTitle("Latest Completed Jobs"); $sql = "SELECT id, webcam_image_id FROM jobs WHERE webcam_image_id != 0 AND status = 'complete' ORDER BY finished_time DESC"; $available = new Collection($sql); $available->bindType('id', 'Job'); $available->bindType('webcam_image_id', 'StorageInterface'); $this->set('jobs', $available->getRange(0, 24)); }
public static function byContentAndType($id, $type) { if (!array_key_exists($type, self::$types)) { $comments = Collection::none(); } else { //look up the comments $sql = "SELECT id, user_id\n\t\t\t\tFROM comments\n\t\t\t\tWHERE content_id = ?\n\t\t\t\tAND content_type = ?\n\t\t\t\tORDER BY comment_date ASC\n\t\t\t"; $comments = new Collection($sql, array($id, $type)); } $comments->bindType('id', 'Comment'); $comments->bindType('user_id', 'User'); return $comments; }
public static function byContentAndType($id, $type) { //some validation $id = (int) $id; if (!in_array($type, array('job', 'bot'))) { return new Comment(); } //look up the comments $sql = "SELECT id, user_id\n\t\t\t\tFROM comments\n\t\t\t\tWHERE content_id = ?\n\t\t\t\tAND content_type = ?\n \t\tORDER BY comment_date ASC\n\t\t\t"; $comments = new Collection($sql, array($id, $type)); $comments->bindType('id', 'Comment'); $comments->bindType('user_id', 'User'); return $comments; }
public function getChildren() { $sql = "SELECT id\n\t\t \tFROM s3_files\n\t\t \tWHERE parent_id = ?\n\t\t \tORDER BY id DESC"; $children = new Collection($sql, array($this->id)); $children->bindType('id', get_class($this)); return $children; }
public static function getStream(User $user) { $sql = "SELECT id\n\t\t\t\tFROM activities\n\t\t\t\tWHERE user_id = ?\n\t\t\t\tORDER BY id DESC\n\t\t\t"; $stream = new Collection($sql, array($user->id)); $stream->bindType('id', 'Activity'); return $stream; }
public function getSliceJobs() { $sql = "SELECT id\n \t\tFROM slice_jobs\n \t\tWHERE slice_config_id = ?\n \t\tORDER BY id DESC"; $sliceJobs = new Collection($sql, array($this->id)); $sliceJobs->bindType('id', 'SliceJob'); return $sliceJobs; }
public static function getStream(User $user) { $sql = "SELECT activity, action_date\n\t\t\t\tFROM activities\n\t\t\t\tWHERE user_id = ?\n\t\t\t\tORDER BY id DESC\n\t\t\t"; $stream = new Collection($sql, array($user->id)); $stream->bindValue('activity'); $stream->bindType('action_date', 'DateTime'); $stream->bindData('user_link', $user->getLink()); return $stream; }
public static function getMine($all = false) { if (User::isLoggedIn()) { $sql = "SELECT id FROM notifications WHERE id > ? AND (to_user_id = ? or to_user_id IS NULL)"; $data = array(); if ($all === false) { $data[] = User::$me->get('last_notification'); } else { $data[] = 0; // Get all of them } $data[] = User::$me->id; $notifications = new Collection($sql, $data); $notifications->bindType('id', 'Notification'); return $notifications; } else { // Return empty collection return Collection::none(); } }
public function live() { $this->assertAdmin(); $this->setTitle("Live Bots View"); $sql = "SELECT id, queue_id, job_id FROM bots WHERE webcam_image_id != 0 AND last_seen > NOW() - 3600 ORDER BY last_seen DESC"; $bots = new Collection($sql); $bots->bindType('id', 'Bot'); $bots->bindType('queue_id', 'Queue'); $bots->bindType('job_id', 'Job'); $this->set('bots', $bots->getRange(0, 24)); $this->set('dashboard_style', 'medium_thumbnails'); }
public function getErrorLog() { $sql = "SELECT id\n\t\t \tFROM error_log\n\t\t \tWHERE bot_id = ?\n\t\t \tORDER BY error_date DESC"; $logs = new Collection($sql, array($this->id)); $logs->bindType('id', 'ErrorLog'); return $logs; }
public function getMyConfigs() { $sql = "SELECT id\n\t\t \tFROM slice_configs\n\t\t \tWHERE engine_id = ?\n\t\t \tAND (user_id = ? OR id = ?)\n\t\t \tORDER BY config_name"; $configs = new Collection($sql, array($this->id, User::$me->id, $this->get('default_config_id'))); $configs->bindType('id', 'SliceConfig'); return $configs; }
public static function getJobsRequiringAction() { $sql = "SELECT id, input_id, job_id\n\t\t \tFROM slice_jobs\n\t\t \tWHERE status = 'pending'\n\t\t \tORDER BY finish_date ASC"; $jobs = new Collection($sql); $jobs->bindType('id', 'SliceJob'); $jobs->bindType('input_id', STORAGE_METHOD); $jobs->bindType('job_id', 'Job'); return $jobs; }
public function getApps() { $sql = "SELECT id\n\t\t\t\tFROM oauth_token\n\t\t\t\tWHERE consumer_id = ?\n\t\t\t\tAND user_id = ?"; $apps = new Collection($sql, array($this->id, User::$me->id)); $apps->bindType('id', 'OAuthToken'); return $apps; }
public function getMySliceConfigs() { $sql = "SELECT id, engine_id\n\t\t\t\tFROM slice_configs\n\t\t\t\tWHERE user_id = ?\n\t\t\t\tORDER BY engine_id DESC"; $configs = new Collection($sql, array($this->id)); $configs->bindType('id', 'SliceConfig'); $configs->bindType('engine_id', 'SliceEngine'); return $configs; }
<?php include "../patches.php"; $patch = new Patch(14); if (!$patch->exists()) { $sql = "CREATE TABLE IF NOT EXISTS `bot_queues` (\n\t\t `queue_id` INT(11) UNSIGNED NOT NULL,\n\t\t `bot_id` INT(11) UNSIGNED NOT NULL,\n\t\t `priority` INT(11) UNSIGNED NOT NULL,\n\t\t PRIMARY KEY (`queue_id`, `bot_id`, `priority`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8"; db()->execute($sql); $sql = "SELECT id, queue_id from bots"; $bots = new Collection($sql); $bots->bindType("id", "Bot"); $bots->bindType("queue_id", "Queue"); foreach ($bots->getAll() as $row) { $bot = $row['Bot']; $queue = $row['Queue']; $sql = "INSERT INTO bot_queues VALUES(?, ?, 1)"; $data = array($queue->id, $bot->id); db()->execute($sql, $data); } $sql = "DROP INDEX queue_id ON bots"; db()->execute($sql); $sql = "ALTER TABLE bots DROP COLUMN queue_id"; db()->execute($sql); $patch->finish("Added bots to queues"); }
<?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);
public function getQueues() { $sql = "SELECT queue_id\n\t\t\t\tFROM bot_queues\n\t\t\t\tWHERE bot_id = ?\n\t\t\t\tORDER BY priority ASC"; $data = array($this->id); $queues = new Collection($sql, $data); $queues->bindType('queue_id', 'Queue'); return $queues; }
public static function getJobsRequiringAction() { $sql = "SELECT id, queue_id, bot_id\n\t\t\t\tFROM jobs\n\t\t\t\tWHERE status = 'qa'\n\t\t\t\tORDER BY finished_time ASC"; $jobs = new Collection($sql); $jobs->bindType('id', 'Job'); $jobs->bindType('queue_id', 'Queue'); $jobs->bindType('bot_id', 'Bot'); return $jobs; }
public static function getQueuedEmails() { $sql = "SELECT id\n\t\t\t\tFROM email_queue\n\t\t\t\tWHERE status = 'queued'\n\t\t\t\tORDER BY queue_date ASC"; $emails = new Collection($sql); $emails->bindType('id', 'Email'); return $emails; }