Esempio n. 1
0
 static function update_overlays($task)
 {
     $errors = array();
     try {
         $mode = $task->get('mode', 'init');
         switch ($mode) {
             case 'init':
                 $q = emboss::find_dirty();
                 foreach ($q as $item) {
                     $ids[] = array('id' => $item->id, 'image_id' => $item->image_id, 'overlay_id' => $item->best_overlay_id);
                 }
                 $count = count($ids);
                 if ($count > 0) {
                     $task->set('ids', $ids);
                     $task->set('count', $count);
                     $task->set('current', 0);
                     $task->set('mode', 'continue');
                 } else {
                     $task->done = true;
                     $task->state = 'success';
                     $task->percent_complete = 100;
                     site_status::clear('emboss_dirty');
                     return;
                 }
                 break;
             case 'continue':
                 $ids = $task->get('ids');
                 $count = $task->get('count');
                 $current = $task->get('current');
                 break;
         }
         $i = 1 * $current;
         $id = $ids[$i];
         $current++;
         $task->set('current', $current);
         emboss_task::do_embossing($id['id'], $id['image_id'], $id['overlay_id']);
         if ($current >= $count) {
             $task->done = true;
             $task->state = 'success';
             $task->percent_complete = 100;
             $task->status = 'Complete';
             site_status::clear('emboss_dirty');
         } else {
             $task->percent_complete = $current / $count * 100;
             $task->status = t("Reembossed {$current} of {$count} photos");
         }
     } catch (Exception $e) {
         Kohana_Log::add('error', (string) $e);
         $task->done = true;
         $task->state = 'error';
         $task->status = $e->getMessage();
         $errors[] = (string) $e;
     }
     if ($errors) {
         $task->log($errors);
     }
 }
Esempio n. 2
0
 static function check_for_dirty()
 {
     $q = emboss::find_dirty();
     $n = $q->count();
     if ($n > 0) {
         $url = url::site('admin/maintenance/start/emboss_task::update_overlays?csrf=__CSRF__');
         site_status::warning(t2("One of your photos needs to be (re)embossed. <a %attrs>Click here to fix it</a>", "%count of your photos need to be (re)embossed. <a %attrs>Click here to fix them</a>", $n, array('attrs' => html::mark_clean(sprintf('href="%s" class="g-dialog-link"', $url)))), 'emboss_dirty');
     } else {
         site_status::clear('emboss_dirty');
     }
 }