summaryrefslogtreecommitdiff
path: root/core/helpers/batch.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-03-04 08:51:49 +0000
committerBharat Mediratta <bharat@menalto.com>2009-03-04 08:51:49 +0000
commit23b0abb9742d3418484fe8d01609f6849d7960ce (patch)
tree917e2816d561036055769c1723382ab0de4f6431 /core/helpers/batch.php
parentb493a534f2966e23eb0244654e8929320721da8e (diff)
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.
Diffstat (limited to 'core/helpers/batch.php')
-rw-r--r--core/helpers/batch.php24
1 files changed, 12 insertions, 12 deletions
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;
}
}