summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/controllers/scaffold.php10
-rw-r--r--core/controllers/simple_uploader.php8
-rw-r--r--core/helpers/batch.php24
3 files changed, 21 insertions, 21 deletions
diff --git a/core/controllers/scaffold.php b/core/controllers/scaffold.php
index bd4c1f22..76b4ff71 100644
--- a/core/controllers/scaffold.php
+++ b/core/controllers/scaffold.php
@@ -201,8 +201,7 @@ class Scaffold_Controller extends Template_Controller {
throw new Exception("@todo BAD_ALBUM");
}
- batch::operation("add", $parent);
-
+ batch::start();
cookie::set("add_photos_path", $path);
$photo_count = 0;
foreach (glob("$path/*.[Jj][Pp][Gg]") as $file) {
@@ -210,7 +209,7 @@ class Scaffold_Controller extends Template_Controller {
photo::create($parent, $file, basename($file), basename($file));
$photo_count++;
}
- batch::end_operation("add");
+ batch::stop();
if ($photo_count > 0) {
log::success("content", "(scaffold) Added $photo_count photos",
@@ -227,8 +226,7 @@ class Scaffold_Controller extends Template_Controller {
$test_images = glob(APPPATH . "tests/images/*.[Jj][Pp][Gg]");
- batch::operation("add", ORM::factory("item", 1));
-
+ batch::start();
$album_count = $photo_count = 0;
for ($i = 0; $i < $count; $i++) {
set_time_limit(30);
@@ -252,7 +250,7 @@ class Scaffold_Controller extends Template_Controller {
$photo_count++;
}
}
- batch::end_operation("add");
+ batch::stop();
if ($photo_count > 0) {
log::success("content", "(scaffold) Added $photo_count photos");
diff --git a/core/controllers/simple_uploader.php b/core/controllers/simple_uploader.php
index 38eb5c38..0e2368e2 100644
--- a/core/controllers/simple_uploader.php
+++ b/core/controllers/simple_uploader.php
@@ -40,6 +40,10 @@ class Simple_Uploader_Controller extends Controller {
print $v;
}
+ public function start() {
+ batch::start();
+ }
+
public function add_photo($id) {
$album = ORM::factory("item", $id);
access::required("edit", $album);
@@ -48,7 +52,6 @@ class Simple_Uploader_Controller extends Controller {
$file_validation = new Validation($_FILES);
$file_validation->add_rules("file", "upload::valid", "upload::type[gif,jpg,png,flv,mp4]");
if ($file_validation->validate()) {
- batch::operation("add", $album);
$temp_filename = upload::save("file");
$title = substr(basename($temp_filename), 10); // Skip unique identifier Kohana adds
$path_info = pathinfo($temp_filename);
@@ -65,8 +68,7 @@ class Simple_Uploader_Controller extends Controller {
}
public function finish() {
- batch::end_operation("add");
-
+ batch::stop();
print json_encode(array("result" => "success"));
}
}
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;
}
}