} if (!defined("AMAZON_AWS_SECRET")) { die("Please define the AMAZON_AWS_SECRET in your config\n"); } if (!defined("STORAGE_METHOD") || STORAGE_METHOD !== "LocalFile") { die("Please define STORAGE_METHOD to be LocalFile\n"); } $total_s3_files = db()->getValue("SELECT max(id) FROM s3_files"); print "Files to convert: " . $total_s3_files . "\n"; $rows_to_remove = array(); for ($s3_id = 1; $s3_id <= $total_s3_files; $s3_id++) { // Grab the s3 file // Verify the file exists. // If it exists, download it // If it doesn't, add it to the rows to be removed // Set all of the correct variables $s3_file = new S3File($s3_id); if ($s3_file->exists()) { $local_file = new LocalFile($s3_id); $temp_file = tempnam("/tmp", "BQ"); $s3_file->download($s3_file->get('path'), $temp_file); $local_file->upload($temp_file, $s3_file->get('path')); $local_file->id = $s3_id; $percent_completed = sprintf("%01.2f", $s3_id * 100 / $total_s3_files); print sprintf("%6s", $percent_completed) . "% => File #" . $s3_id . "\n"; } else { print "File #" . $s3_id . " doesn't exist\n"; $rows_to_remove[] = $s3_id; } } print count($rows_to_remove) . " files were no longer in S3\n";
public function create() { $this->assertLoggedIn(); if ($this->args('step2')) { $this->setTitle('Step 2 of 2: Create Job'); } else { $this->setTitle('Create new Job'); } try { if ($this->args('job_id')) { $job = new Job($this->args('job_id')); if (!$job->isHydrated()) { throw new Exception("That job does not exist."); } if ($job->get('user_id') != User::$me->id) { throw new Exception("You do not own this job."); } $file = $job->getFile(); $queue_id = $job->get('queue_id'); } else { $file = new S3File($this->args('file_id')); } if (!$file->isHydrated()) { throw new Exception("That file does not exist."); } if ($file->get('user_id') != User::$me->id) { throw new Exception("You do not have access to this file."); } $this->set('file', $file); //load up our form. $form = $this->_createJobForm($file, $queue_id); if (isset($job)) { $form->action = "/job/create/job:{$job->id}"; } else { $form->action = "/job/create/file:{$file->id}"; } //handle our form if ($form->checkSubmitAndValidate($this->args())) { //pull in our quantity $quantity = (int) $form->data('quantity'); $quantity = max(1, $quantity); $quantity = min(1000, $quantity); //queue error checking. $queue = new Queue($form->data('queue_id')); if (!$queue->isHydrated()) { throw new Exception("That queue does not exist."); } if (!$queue->canAdd()) { throw new Exception("You do not have permission to add to that queue."); } //okay, we good? $queue->addGCodeFile($file, $quantity); Activity::log("added {$quantity} new " . Utility::pluralizeWord('job', $quantity)); $this->forwardToUrl($queue->getUrl()); } $this->set('form', $form); } catch (Exception $e) { $this->set('megaerror', $e->getMessage()); } }