From 39cf3c2b046b03691937e112268403130508da63 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 21 Jun 2009 08:52:26 -0700 Subject: The start of the digibug printing module. The first cut at the administration panels. This is still a work in progress. --- modules/digibug/helpers/digibug_installer.php | 43 +++++++++++++++++++++++++++ modules/digibug/helpers/digibug_menu.php | 42 ++++++++++++++++++++++++++ modules/digibug/helpers/digibug_theme.php | 25 ++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 modules/digibug/helpers/digibug_installer.php create mode 100644 modules/digibug/helpers/digibug_menu.php create mode 100644 modules/digibug/helpers/digibug_theme.php (limited to 'modules/digibug/helpers') diff --git a/modules/digibug/helpers/digibug_installer.php b/modules/digibug/helpers/digibug_installer.php new file mode 100644 index 00000000..90dab990 --- /dev/null +++ b/modules/digibug/helpers/digibug_installer.php @@ -0,0 +1,43 @@ +query("CREATE TABLE {print_proxy} ( + `id` int(9) NOT NULL auto_increment, + `proxy_id` char(55) NOT NULL, + `item_id` int(9), + PRIMARY KEY (`id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + module::set_var("digibug", "basic_company_id", "3153"); + module::set_var("digibug", "basic_event_id", "8491"); + module::set_var("digibug", "mode", "basic"); + + module::set_version("digibug", 1); + } + } + + static function uninstall() { + Database::instance()->query("DROP TABLE IF EXISTS {print_proxy}"); + module::delete("digibug"); + } +} diff --git a/modules/digibug/helpers/digibug_menu.php b/modules/digibug/helpers/digibug_menu.php new file mode 100644 index 00000000..3f41bb16 --- /dev/null +++ b/modules/digibug/helpers/digibug_menu.php @@ -0,0 +1,42 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("digibug_menu") + ->label(t("Digibug Administration")) + ->url(url::site("admin/digibug"))); + } + + static function photo($menu, $theme) { + } + + static function site($menu, $theme) { + $item = $theme->item(); + + if ($item && access::can("edit", $item)) { + $options_menu = $menu->get("options_menu") + ->append(Menu::factory("dialog") + ->id("digibug") + ->label(t("Peform Digibug Processing")) + ->url(url::site("digibug/index/$item->id"))); + } + } +} diff --git a/modules/digibug/helpers/digibug_theme.php b/modules/digibug/helpers/digibug_theme.php new file mode 100644 index 00000000..06d656c8 --- /dev/null +++ b/modules/digibug/helpers/digibug_theme.php @@ -0,0 +1,25 @@ +"; + } +} -- cgit v1.2.3 From f981484a8051c0d5d05dae55882aefdb7094403a Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 22 Jun 2009 05:52:47 -0700 Subject: Add a digibug printing button to the quick pane --- modules/digibug/helpers/digibug_quick.php | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 modules/digibug/helpers/digibug_quick.php (limited to 'modules/digibug/helpers') diff --git a/modules/digibug/helpers/digibug_quick.php b/modules/digibug/helpers/digibug_quick.php new file mode 100644 index 00000000..dce0c519 --- /dev/null +++ b/modules/digibug/helpers/digibug_quick.php @@ -0,0 +1,34 @@ +type == "photo") { + $csrf = access::csrf_token(); + $elements["center"][] = (object)array( + "title" => t("Print photo with Digibug"), + "class" => "gButtonLink", + "icon" => "ui-icon-print", + "href" => url::site("digibug/print/$item->id?csrf=$csrf")); + } + + return $elements; + } +} -- cgit v1.2.3 From 05f8659a7ffa35cb1458c69e4db1196aa384fff0 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 22 Jun 2009 06:03:55 -0700 Subject: Fix preamble so tests pass --- modules/digibug/controllers/admin_digibug.php | 3 ++- modules/digibug/controllers/digibug.php | 5 +++-- modules/digibug/helpers/digibug_installer.php | 3 ++- modules/digibug/helpers/digibug_menu.php | 7 ++++--- 4 files changed, 11 insertions(+), 7 deletions(-) (limited to 'modules/digibug/helpers') diff --git a/modules/digibug/controllers/admin_digibug.php b/modules/digibug/controllers/admin_digibug.php index 86338f6b..8263fc83 100644 --- a/modules/digibug/controllers/admin_digibug.php +++ b/modules/digibug/controllers/admin_digibug.php @@ -1,4 +1,5 @@ - $form->__toString())); } } - + private function _get_form() { $form = new Forge("digibug/handler", "", "post", array("id" => "gDigibugForm")); diff --git a/modules/digibug/helpers/digibug_installer.php b/modules/digibug/helpers/digibug_installer.php index 90dab990..33b5107b 100644 --- a/modules/digibug/helpers/digibug_installer.php +++ b/modules/digibug/helpers/digibug_installer.php @@ -1,4 +1,5 @@ -label(t("Digibug Administration")) ->url(url::site("admin/digibug"))); } - + static function photo($menu, $theme) { } - + static function site($menu, $theme) { $item = $theme->item(); -- cgit v1.2.3 From 58d5624e401f1c369cbbf913008775bc5a165570 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 22 Jun 2009 21:51:22 -0700 Subject: This commit moves a little further along the path: 1) moves the print button from the quick pane to thumb_bottom 2) Creates an entry into the proxy table --- modules/digibug/controllers/digibug.php | 64 ++++++++++++++++++--------- modules/digibug/css/digibug.css | 3 ++ modules/digibug/helpers/digibug.php | 57 ++++++++++++++++++++++++ modules/digibug/helpers/digibug_installer.php | 6 +-- modules/digibug/helpers/digibug_quick.php | 34 -------------- modules/digibug/helpers/digibug_theme.php | 23 ++++++++++ modules/digibug/js/digibug.js | 24 ++++++++++ modules/digibug/models/proxy.php | 22 +++++++++ 8 files changed, 175 insertions(+), 58 deletions(-) create mode 100644 modules/digibug/helpers/digibug.php delete mode 100644 modules/digibug/helpers/digibug_quick.php create mode 100644 modules/digibug/js/digibug.js create mode 100644 modules/digibug/models/proxy.php (limited to 'modules/digibug/helpers') diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index f2f3d6cd..f90b88e2 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -18,35 +18,57 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Digibug_Controller extends Controller { - public function index() { - print $this->_get_form(); - } - - public function handler() { + public function print_photo($id) { access::verify_csrf(); - $form = $this->_get_form(); - if ($form->validate()) { - // @todo process the admin form + $item = ORM::factory("item", $id); - message::success(t("Digibug Processing Successfully")); + $proxy = ORM::factory("proxy"); + $proxy->uuid = digibug::uuid(); + $proxy->item_id = $item->id; + $proxy->save(); - print json_encode( - array("result" => "success")); + $url = url::abs_site("digibug/print_proxy/{$proxy->uuid}"); + if (module::get_var("digibug", "mode", "basic")) { + $company_id = module::get_var("digibug", "basic_company_id"); + $event_id = module::get_var("digibug", "basic_event_id"); } else { - print json_encode( - array("result" => "error", - "form" => $form->__toString())); + $company_id = module::get_var("digibug", "company_id"); + $event_id = module::get_var("digibug", "event_id"); } + $digibug_parms = array( + "digibug_api_version" => "100", + "company_id" => $company_id, + "event_id" => $event_id, + "cmd" => "adding", + "return_url" => url::abs_site($this->input->get("return")), + "num_images" => "1", + "image_1" => $url, + "thumb_1" => "$url/thumb", + "image_height_1" => $item->height, + "image_width_1" => $item->width, + "thumb_height_1" => $item->thumb_height, + "thumb_width_1" => $item->thumb_width, + "title" => $item->title); + + Kohana::log("error", Kohana::debug($digibug_parms)); + + message::success( + t("Photo '%title' was submitted for printing.", array("title" => $item->title))); + print json_encode(array("result" => "success", "reload" => 1)); } - private function _get_form() { - $form = new Forge("digibug/handler", "", "post", - array("id" => "gDigibugForm")); - $group = $form->group("group")->label(t("Digibug Handler")); - $group->input("text")->label(t("Text"))->rules("required"); - $group->submit("submit")->value(t("Submit")); + public function print_proxy($id, $thumb=null) { + + // We don't need to save the session for this request + Session::abort_save(); - return $form; + // Dump out the image + header("Content-Type: $item->mime_type"); + Kohana::close_buffers(false); + $fd = fopen($file, "rb"); + fpassthru($fd); + fclose($fd); } + } \ No newline at end of file diff --git a/modules/digibug/css/digibug.css b/modules/digibug/css/digibug.css index f5cd6717..a09e4551 100644 --- a/modules/digibug/css/digibug.css +++ b/modules/digibug/css/digibug.css @@ -84,5 +84,8 @@ width: 180px; } +.gDigibugPrintButton { + float: left; +} diff --git a/modules/digibug/helpers/digibug.php b/modules/digibug/helpers/digibug.php new file mode 100644 index 00000000..46c9d945 --- /dev/null +++ b/modules/digibug/helpers/digibug.php @@ -0,0 +1,57 @@ +> 4; + $time_hi_and_version = $time_hi_and_version | 0x4000; + + /** + * Set the two most significant bits (bits 6 and 7) of the + * clock_seq_hi_and_reserved to zero and one, respectively. + */ + $clock_seq_hi_and_reserved = hexdec ( $clock_seq_hi_and_reserved ); + $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved >> 2; + $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved | 0x8000; + + return sprintf ('%08s-%04s-%04x-%04x-%012s', + $time_low, $time_mid, $time_hi_and_version, $clock_seq_hi_and_reserved, $node); + } +} diff --git a/modules/digibug/helpers/digibug_installer.php b/modules/digibug/helpers/digibug_installer.php index 33b5107b..73645eb7 100644 --- a/modules/digibug/helpers/digibug_installer.php +++ b/modules/digibug/helpers/digibug_installer.php @@ -22,9 +22,9 @@ class digibug_installer { $version = module::get_version("digibug"); if ($version == 0) { Database::instance() - ->query("CREATE TABLE {print_proxy} ( + ->query("CREATE TABLE {proxies} ( `id` int(9) NOT NULL auto_increment, - `proxy_id` char(55) NOT NULL, + `uuid` char(32) NOT NULL, `item_id` int(9), PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); @@ -38,7 +38,7 @@ class digibug_installer { } static function uninstall() { - Database::instance()->query("DROP TABLE IF EXISTS {print_proxy}"); + Database::instance()->query("DROP TABLE IF EXISTS {proxys}"); module::delete("digibug"); } } diff --git a/modules/digibug/helpers/digibug_quick.php b/modules/digibug/helpers/digibug_quick.php deleted file mode 100644 index dce0c519..00000000 --- a/modules/digibug/helpers/digibug_quick.php +++ /dev/null @@ -1,34 +0,0 @@ -type == "photo") { - $csrf = access::csrf_token(); - $elements["center"][] = (object)array( - "title" => t("Print photo with Digibug"), - "class" => "gButtonLink", - "icon" => "ui-icon-print", - "href" => url::site("digibug/print/$item->id?csrf=$csrf")); - } - - return $elements; - } -} diff --git a/modules/digibug/helpers/digibug_theme.php b/modules/digibug/helpers/digibug_theme.php index 06d656c8..2e44b115 100644 --- a/modules/digibug/helpers/digibug_theme.php +++ b/modules/digibug/helpers/digibug_theme.php @@ -18,8 +18,31 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class digibug_theme_Core { + static function head($theme) { + $head[] = ""; + $head[] = html::script("modules/digibug/js/digibug.js");; + return implode("\n", $head); + } + static function admin_head($theme) { return ""; } + + static function thumb_bottom($theme, $child) { + if ($theme->page_type() == "album" && $child->type == "photo") { + $csrf = access::csrf_token(); + $return = "album/{$child->parent()->id}"; + $href = url::site("digibug/print_photo/$child->id?csrf={$csrf}&return=$return"); + $title = t("Print photo with Digibug"); + return ""; + } + return ""; + } } diff --git a/modules/digibug/js/digibug.js b/modules/digibug/js/digibug.js new file mode 100644 index 00000000..f30678c0 --- /dev/null +++ b/modules/digibug/js/digibug.js @@ -0,0 +1,24 @@ +$(document).ready(function() { + $(".gDigibugPrintButton a").click(function(e) { + e.preventDefault(); + queue_print(e); + }); +}); + +function queue_print(e) { + var parent = e.currentTarget.parentNode; + $(parent).addClass("gLoadingLarge"); + $.ajax({ + type: "GET", + url: e.currentTarget.href, + dataType: "json", + success: function(data) { + $(parent).removeClass("gLoadingLarge"); + if (data.location) { + window.location = data.location; + } else if (data.reload) { + window.location.reload(); + } + } + }); +}; diff --git a/modules/digibug/models/proxy.php b/modules/digibug/models/proxy.php new file mode 100644 index 00000000..ce10c592 --- /dev/null +++ b/modules/digibug/models/proxy.php @@ -0,0 +1,22 @@ + Date: Tue, 23 Jun 2009 06:06:33 -0700 Subject: This change implements the print_proxy method. This method allows a 1 time security bypass for the remote print processor to retrieve the fullsize image. --- modules/digibug/controllers/digibug.php | 25 ++++++++++++++++++++++--- modules/digibug/helpers/digibug_theme.php | 15 +++++---------- 2 files changed, 27 insertions(+), 13 deletions(-) (limited to 'modules/digibug/helpers') diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index f90b88e2..b0807aa5 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -51,24 +51,43 @@ class Digibug_Controller extends Controller { "thumb_width_1" => $item->thumb_width, "title" => $item->title); - Kohana::log("error", Kohana::debug($digibug_parms)); - message::success( t("Photo '%title' was submitted for printing.", array("title" => $item->title))); print json_encode(array("result" => "success", "reload" => 1)); } public function print_proxy($id, $thumb=null) { + $proxy = ORM::factory("proxy") + ->where("uuid", $id) + ->find(); + + if (!$proxy->loaded) { + Kohana::show_404(); + } + + if (!$proxy->item->loaded) { + Kohana::show_404(); + } + + $file = empty($thumb) ? $proxy->item->file_path() : $proxy->item->thumb_path(); + if (!file_exists($file)) { + kohana::show_404(); + } // We don't need to save the session for this request Session::abort_save(); // Dump out the image - header("Content-Type: $item->mime_type"); + header("Content-Type: $proxy->item->mime_type"); Kohana::close_buffers(false); $fd = fopen($file, "rb"); fpassthru($fd); fclose($fd); + + // If the request was for the image and not the thumb, then delete the proxy. + if (empty($thumb)) { + $proxy->delete(); + } } } \ No newline at end of file diff --git a/modules/digibug/helpers/digibug_theme.php b/modules/digibug/helpers/digibug_theme.php index 2e44b115..0fe2ce2e 100644 --- a/modules/digibug/helpers/digibug_theme.php +++ b/modules/digibug/helpers/digibug_theme.php @@ -32,16 +32,11 @@ class digibug_theme_Core { static function thumb_bottom($theme, $child) { if ($theme->page_type() == "album" && $child->type == "photo") { - $csrf = access::csrf_token(); - $return = "album/{$child->parent()->id}"; - $href = url::site("digibug/print_photo/$child->id?csrf={$csrf}&return=$return"); - $title = t("Print photo with Digibug"); - return ""; + $v = new View("digibug_album.html"); + $v->id = $child->id; + $v->return = "album/{$child->parent()->id}"; + $v->title = t("Print photo with Digibug"); + return $v->render(); } return ""; } -- cgit v1.2.3 From 231ad4f32950f42c76c16ab453246bedea8abf2c Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 23 Jun 2009 22:13:28 -0700 Subject: This implements the Digibug printing. When a a print request is made the digibug shopping cart is opened in a new window. When the cart is emptied, the window is closed. Users can close the window by pressing the continue shopping button --- modules/digibug/controllers/digibug.php | 12 ++++--- modules/digibug/helpers/digibug_installer.php | 2 +- modules/digibug/helpers/digibug_theme.php | 1 - modules/digibug/js/digibug.js | 52 +++++++++++++++++++-------- modules/digibug/views/digibug_album.html.php | 2 +- modules/digibug/views/digibug_form.html.php | 16 +++++++++ 6 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 modules/digibug/views/digibug_form.html.php (limited to 'modules/digibug/helpers') diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index b0807aa5..609da875 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -36,12 +36,13 @@ class Digibug_Controller extends Controller { $company_id = module::get_var("digibug", "company_id"); $event_id = module::get_var("digibug", "event_id"); } - $digibug_parms = array( + $v = new View("digibug_form.html"); + $v->order_parms = array( "digibug_api_version" => "100", "company_id" => $company_id, "event_id" => $event_id, "cmd" => "adding", - "return_url" => url::abs_site($this->input->get("return")), + "return_url" => url::abs_site("digibug/close_window"), "num_images" => "1", "image_1" => $url, "thumb_1" => "$url/thumb", @@ -51,9 +52,7 @@ class Digibug_Controller extends Controller { "thumb_width_1" => $item->thumb_width, "title" => $item->title); - message::success( - t("Photo '%title' was submitted for printing.", array("title" => $item->title))); - print json_encode(array("result" => "success", "reload" => 1)); + print $v; } public function print_proxy($id, $thumb=null) { @@ -90,4 +89,7 @@ class Digibug_Controller extends Controller { } } + public function close_window() { + print ""; + } } \ No newline at end of file diff --git a/modules/digibug/helpers/digibug_installer.php b/modules/digibug/helpers/digibug_installer.php index 73645eb7..0476e2cc 100644 --- a/modules/digibug/helpers/digibug_installer.php +++ b/modules/digibug/helpers/digibug_installer.php @@ -24,7 +24,7 @@ class digibug_installer { Database::instance() ->query("CREATE TABLE {proxies} ( `id` int(9) NOT NULL auto_increment, - `uuid` char(32) NOT NULL, + `uuid` char(36) NOT NULL, `item_id` int(9), PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); diff --git a/modules/digibug/helpers/digibug_theme.php b/modules/digibug/helpers/digibug_theme.php index 0fe2ce2e..e52fcc7f 100644 --- a/modules/digibug/helpers/digibug_theme.php +++ b/modules/digibug/helpers/digibug_theme.php @@ -34,7 +34,6 @@ class digibug_theme_Core { if ($theme->page_type() == "album" && $child->type == "photo") { $v = new View("digibug_album.html"); $v->id = $child->id; - $v->return = "album/{$child->parent()->id}"; $v->title = t("Print photo with Digibug"); return $v->render(); } diff --git a/modules/digibug/js/digibug.js b/modules/digibug/js/digibug.js index f30678c0..e9e8933e 100644 --- a/modules/digibug/js/digibug.js +++ b/modules/digibug/js/digibug.js @@ -5,20 +5,42 @@ $(document).ready(function() { }); }); +function popUp(url, options) { + options = $.extend({ + /* default options */ + width: 400, + height: 400, + target: 'dbPopWin', + scrollbars: 'yes', + resizable: 'no', + menuBar: 'no', + addressBar: 'yes'}, options); + + /* center the window by default. */ + if (!options.winY) { + options.winY = screen.height / 2 - options.height / 2; + }; + if (!options.winX) { + options.winX = screen.width / 2 - options.width / 2; + }; + + open( + url, + options['target'], + 'width= ' + options.width + + ',height=' + options.height + + ',top=' + options.winY + + ',left=' + options.winX + + ',scrollbars=' + options.scrollbars + + ',resizable=' + options.resizable + + ',menubar=' + options.menuBar + + ',location=' + options.addressBar + ); + + return false; + +} + function queue_print(e) { - var parent = e.currentTarget.parentNode; - $(parent).addClass("gLoadingLarge"); - $.ajax({ - type: "GET", - url: e.currentTarget.href, - dataType: "json", - success: function(data) { - $(parent).removeClass("gLoadingLarge"); - if (data.location) { - window.location = data.location; - } else if (data.reload) { - window.location.reload(); - } - } - }); + return popUp(e.currentTarget.href, { width: 800, height: 600 } ); }; diff --git a/modules/digibug/views/digibug_album.html.php b/modules/digibug/views/digibug_album.html.php index 0f1537e9..c3337324 100644 --- a/modules/digibug/views/digibug_album.html.php +++ b/modules/digibug/views/digibug_album.html.php @@ -1,7 +1,7 @@
" + href="" title=""> diff --git a/modules/digibug/views/digibug_form.html.php b/modules/digibug/views/digibug_form.html.php new file mode 100644 index 00000000..c2cd889e --- /dev/null +++ b/modules/digibug/views/digibug_form.html.php @@ -0,0 +1,16 @@ + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3 From 0062f8a24a62fe8f5abdffcea8c35382afa32244 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 24 Jun 2009 05:47:58 -0700 Subject: Add a timestamp column to the proxies table. --- modules/digibug/helpers/digibug_installer.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'modules/digibug/helpers') diff --git a/modules/digibug/helpers/digibug_installer.php b/modules/digibug/helpers/digibug_installer.php index 0476e2cc..baff2075 100644 --- a/modules/digibug/helpers/digibug_installer.php +++ b/modules/digibug/helpers/digibug_installer.php @@ -23,9 +23,10 @@ class digibug_installer { if ($version == 0) { Database::instance() ->query("CREATE TABLE {proxies} ( - `id` int(9) NOT NULL auto_increment, + `id` int(9) NOT NULL AUTO_INCREMENT, `uuid` char(36) NOT NULL, - `item_id` int(9), + `request_date` TIMESTAMP NOT NULL DEFAULT current_timestamp, + `item_id` int(9) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); @@ -38,7 +39,7 @@ class digibug_installer { } static function uninstall() { - Database::instance()->query("DROP TABLE IF EXISTS {proxys}"); + Database::instance()->query("DROP TABLE IF EXISTS {proxies}"); module::delete("digibug"); } } -- cgit v1.2.3 From 40e27e128e34601380079a02dca9346aed54c3bf Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 24 Jun 2009 13:11:53 -0700 Subject: Create a maintenance task that allows the administrator to remove any proxy requests that are still active after 10 days. Digibug requires that the image be available for 5 days, so we'll give them an extra 5 days. Also correct a few issues with the protocol. --- modules/digibug/controllers/digibug.php | 4 +- modules/digibug/helpers/digibug_task.php | 68 ++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 modules/digibug/helpers/digibug_task.php (limited to 'modules/digibug/helpers') diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index 609da875..3a427149 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -41,7 +41,7 @@ class Digibug_Controller extends Controller { "digibug_api_version" => "100", "company_id" => $company_id, "event_id" => $event_id, - "cmd" => "adding", + "cmd" => "addimg", "return_url" => url::abs_site("digibug/close_window"), "num_images" => "1", "image_1" => $url, @@ -50,7 +50,7 @@ class Digibug_Controller extends Controller { "image_width_1" => $item->width, "thumb_height_1" => $item->thumb_height, "thumb_width_1" => $item->thumb_width, - "title" => $item->title); + "title_1" => $item->title); print $v; } diff --git a/modules/digibug/helpers/digibug_task.php b/modules/digibug/helpers/digibug_task.php new file mode 100644 index 00000000..98f79731 --- /dev/null +++ b/modules/digibug/helpers/digibug_task.php @@ -0,0 +1,68 @@ +query( + "SELECT count(*) as print_requests + FROM {proxies} + WHERE `request_date` <= (CURDATE() - INTERVAL 10 DAY)")->current()->print_requests; + + return array(Task_Definition::factory() + ->callback("digibug_task::remove_expired") + ->name(t("Remove Digibug print requests")) + ->description($expired_request_count + ? t2("1 Digibug print request has expired", + "%count Digibug print requests have expired", + $expired_request_count) + : t("All print requests are current")) + ->severity($expired_request_count ? log::WARNING : log::SUCCESS)); + } + + static function remove_expired($task) { + $completed = $task->get("completed", 0); + $expired = ORM::factory("proxy") + ->where("request_date <= (CURDATE() - INTERVAL 10 DAY)") + ->find_all(); + $remaining = $expired->count(); + + $start = microtime(true); + foreach ($expired as $proxy) { + if (microtime(true) - $start > 1.5) { + break; + } + $proxy->delete(); + $completed++; + $remaining--; + } + + if ($completed + $remaining > 0) { + $task->percent_complete = (int)(100 * $completed / ($completed + $remaining)); + } else { + $task->percent_complete = 100; + } + + $task->set("completed", $completed); + if ($remaining == 0) { + $task->done = true; + $task->state = "success"; + } + } +} -- cgit v1.2.3