From 23b0abb9742d3418484fe8d01609f6849d7960ce Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 4 Mar 2009 08:51:49 +0000 Subject: Redefine the batch API to be very very simple. You call batch::start() before starting a series of events, and batch::stop() when you're done. In batch mode, the notification module will store up pending notifications. When the batch job is complete, it'll send a single digested email to each user for all of her notifications. Updated the scaffold and local_import to use this. Haven't modified SimpleUploader yet. --- core/helpers/batch.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'core/helpers/batch.php') diff --git a/core/helpers/batch.php b/core/helpers/batch.php index 98523f30..23c9e196 100644 --- a/core/helpers/batch.php +++ b/core/helpers/batch.php @@ -17,24 +17,24 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ - class batch_Core { - static function operation($name, $item) { - if (!self::in_progress($name)) { - Session::instance()->set("operation_$name", "1"); - module::event("operation", $name, $item); - } + static function start() { + $session = Session::instance(); + $session->set("batch_level", $session->get("batch_level", 0) + 1); } - static function end_operation($name) { - if (self::in_progress($name)) { - module::event("end_operation", $name); - Session::instance()->set("operation_$name", null); + static function stop($name) { + $session = Session::instance(); + $batch_level = $session->get("batch_level", 0) - 1; + if ($batch_level > 0) { + $session->set("batch_level", $batch_level); + } else { + $session->delete("batch_level"); + module::event("batch_complete"); } } static function in_progress($name) { - $value = Session::instance()->get("operation_$name", null); - return !empty($value); + return Session::instance()->get("batch_level", 0) > 0; } } -- cgit v1.2.3