1
0

fixed a couple of bugs in aws_s3 v2

This commit is contained in:
danneh3826 2011-01-22 22:22:13 +00:00
parent c124637b52
commit 638779a6f8
2 changed files with 24 additions and 6 deletions

View File

@ -64,6 +64,24 @@ class aws_s3_Core {
fwrite($fh, date("Y-m-d H:i:s") . ": " . $item . "\n"); fwrite($fh, date("Y-m-d H:i:s") . ": " . $item . "\n");
fclose($fh); fclose($fh);
} }
static function get_upload_flags() {
$flags = 0;
if (module::get_var("aws_s3", "upload_thumbs") == 1) {
aws_s3::log("can upload thumbs");
$flags += self::UPLOAD_THUMB;
}
if (module::get_var("aws_s3", "upload_resizes") == 1) {
aws_s3::log("can upload resizes");
$flags += self::UPLOAD_RESIZE;
}
if (module::get_var("aws_s3", "upload_fullsizes") == 1) {
aws_s3::log("can upload full sizes");
$flags += self::UPLOAD_FULLSIZE;
}
aws_s3::log("flags: " . $flags);
return $flags;
}
static function upload_item($item, $flags = 7) { static function upload_item($item, $flags = 7) {
self::get_s3(); self::get_s3();
@ -75,7 +93,7 @@ class aws_s3_Core {
$itype = "A"; $itype = "A";
} }
if ((!$item->s3_fullsize_uploaded || $flags & aws_s3::UPLOAD_FULLSIZE) && !$item->is_album()) { if (!$item->s3_fullsize_uploaded && $flags & aws_s3::UPLOAD_FULLSIZE && !$item->is_album()) {
aws_s3::log("[" . $itype . ":" . $item->id . "] Uploading fullsize object"); aws_s3::log("[" . $itype . ":" . $item->id . "] Uploading fullsize object");
$success_fs = S3::putObjectFile(VARPATH . "albums/" . $filename, $success_fs = S3::putObjectFile(VARPATH . "albums/" . $filename,
module::get_var("aws_s3", "bucket_name"), module::get_var("aws_s3", "bucket_name"),
@ -86,7 +104,7 @@ class aws_s3_Core {
else else
$success_fs = true; $success_fs = true;
if ((!$item->s3_resize_uploaded || $flags & aws_s3::UPLOAD_RESIZE) && !$item->is_album()) { if (!$item->s3_resize_uploaded && $flags & aws_s3::UPLOAD_RESIZE && !$item->is_album()) {
aws_s3::log("[" . $itype . ":" . $item->id . "] Uploading resize object"); aws_s3::log("[" . $itype . ":" . $item->id . "] Uploading resize object");
$success_rs = S3::putObjectFile(VARPATH . "resizes/" . $filename, $success_rs = S3::putObjectFile(VARPATH . "resizes/" . $filename,
module::get_var("aws_s3", "bucket_name"), module::get_var("aws_s3", "bucket_name"),
@ -97,7 +115,7 @@ class aws_s3_Core {
else else
$success_rs = true; $success_rs = true;
if (!$item->s3_thumb_uploaded || $flags & aws_s3::UPLOAD_THUMB) { if (!$item->s3_thumb_uploaded && $flags & aws_s3::UPLOAD_THUMB) {
aws_s3::log("[" . $itype . ":" . $item->id . "] Uploading thumbnail object"); aws_s3::log("[" . $itype . ":" . $item->id . "] Uploading thumbnail object");
$success_th = S3::putObjectFile(VARPATH . "thumbs/" . $filename, $success_th = S3::putObjectFile(VARPATH . "thumbs/" . $filename,
module::get_var("aws_s3", "bucket_name"), module::get_var("aws_s3", "bucket_name"),

View File

@ -29,7 +29,7 @@ class aws_s3_task_Core {
$task->status = "Commencing upload"; $task->status = "Commencing upload";
$task->percent_complete = 0; $task->percent_complete = 0;
$task->save(); $task->save();
if (aws_s3::upload_item($item)) { if (aws_s3::upload_item($item, aws_s3::get_upload_flags())) {
$task->percent_complete = 100; $task->percent_complete = 100;
$task->done = true; $task->done = true;
$task->state = "success"; $task->state = "success";
@ -102,7 +102,7 @@ class aws_s3_task_Core {
case "upload": { case "upload": {
$items = ORM::factory("item")->find_all($task->get("batch"), $task->get("completed")); $items = ORM::factory("item")->find_all($task->get("batch"), $task->get("completed"));
foreach ($items as $item) { foreach ($items as $item) {
aws_s3::upload_item($item); aws_s3::upload_item($item, aws_s3::get_upload_flags());
$task->set("completed", $task->get("completed") + 1); $task->set("completed", $task->get("completed") + 1);
} }
$task->percent_complete = (90 * ($task->get("completed") / $task->get("total_count"))) + 10; $task->percent_complete = (90 * ($task->get("completed") / $task->get("total_count"))) + 10;
@ -167,7 +167,7 @@ class aws_s3_task_Core {
foreach ($items as $item) { foreach ($items as $item) {
try { try {
if ($item->id > 1) if ($item->id > 1)
aws_s3::upload_item($item); aws_s3::upload_item($item, aws_s3::get_upload_flags());
} }
catch (Exception $err) {} catch (Exception $err) {}
$completed++; $completed++;