Last active
October 13, 2015 03:08
-
-
Save josue/0d0c39bf8a692abf9f42 to your computer and use it in GitHub Desktop.
Test Uploads - Creates temp files and enqueues them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('test_jobs.php'); | |
if (php_sapi_name() === 'cli') { | |
$upload_options = getopt("",array( | |
'upload:', // --upload=5 | |
)); | |
} | |
else if (!empty($_GET['upload'])) { | |
$upload_options = $_GET; | |
} | |
function generate_images($total = 5) { | |
$file_list = array(); | |
for($i = 1; $i <= $total; $i++) { | |
$real_filename = sprintf("ksc_sample_%s.jpg", $i.'_'.time().'_'.rand(1,1000000)); | |
$temp_filename = sprintf("%s.jpg", uniqid('ksc').uniqid()); | |
$file_dest = sprintf("./uploads_tmp/%s", $temp_filename); | |
$file_list[] = array('real'=>$real_filename, 'temp'=>$temp_filename); | |
$img = imagecreatetruecolor(100, 100); | |
$bg_color = imagecolorallocate($img, rand(0,255), rand(0,255), rand(0,255)); | |
imagefill($img, 0, 0, $bg_color); | |
imagejpeg($img, $file_dest); | |
// Free up memory | |
imagedestroy($img); | |
} | |
return $file_list; | |
} | |
$file_list = generate_images($upload_options['upload']); | |
$account_id = 3; | |
$user_id = 240; | |
$folder_id = 435427; | |
$final_file_list = array(); | |
foreach($file_list as $file) { | |
$final_file_list[] = array( | |
"target_name" => $file['temp'], | |
"original_name" => $file['real'], | |
"uploaded_via" => "test_uploads", | |
"folder_id" => $folder_id, | |
"type" => "ts_folder", | |
"app" => "share", | |
"view" => "specific", | |
"model" => "TsFolder", | |
"request_type" => "", | |
"version_id" => "0", | |
"ts_folder_id" => $folder_id, | |
"submit_status" => "0", | |
"account_id" => $account_id, | |
"user_id" => $user_id, | |
"location" => 1, | |
"http_host" => "download.example.com", | |
"user_permission" => array( | |
"admin" => 0, | |
"view" => 0, | |
"download" => 0, | |
"upload" => 0, | |
"approve" => 0, | |
"reject" => 0, | |
"delete" => 0, | |
"um_view" => 0, | |
"um_upload" => 0, | |
"um_approve" => 0, | |
"um_reject" => 0 | |
), | |
"upload_uberlog_id" => uniqid().'.'.rand(1,1000000) | |
); | |
} | |
$options = TestJobs::extractOptions(); | |
$Job = new TestJobs($options); | |
$Job->log('Total Uploads: '.count($final_file_list)); | |
$Job->enqueue($options['queue'], $options['class'], $final_file_list); | |
$Job->runJobs(1, @$options['show_log']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment