From 7cadb4b21b90864b4151481da9aba244d7083788 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 3 Mar 2009 05:59:38 +0000 Subject: Refactored the batch Api: 1) created a small batch helper class: Starting a batch call batch::operation(name, item). In the case of adding photos name = add and item is the parent of the new items. When the operation is finished the batch::end_operation(name) is called. operation and end_operation events are called. Handlers (i.e. item_created) can call batch::in_progress(name) to determine if a batch is being processed. --- core/helpers/batch.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 core/helpers/batch.php (limited to 'core/helpers/batch.php') diff --git a/core/helpers/batch.php b/core/helpers/batch.php new file mode 100644 index 00000000..4411b1b0 --- /dev/null +++ b/core/helpers/batch.php @@ -0,0 +1,40 @@ +set("operation_$name", "1"); + module::event("operation", $name, $item); + } + } + + static function end_operation($name) { + if (self::in_progress($name) === true) { + module::event("end_operation", $name); + Session::instance()->set("operation_$name", null); + } + } + + static function in_progress($name) { + $value = Session::instance()->get("operation_$name", null); + return !empty($value); + } +} -- cgit v1.2.3