Example #1
0
 public function bulkProcess()
 {
     global $wpdb;
     if ($this->_verifiedKey == false) {
         //invalid API Key
         ShortPixelView::displayActivationNotice();
         return;
     }
     $quotaData = $this->checkQuotaAndAlert();
     if (self::getOpt('wp-short-pixel-quota-exceeded', 0) != 0) {
         return;
     }
     if (isset($_POST['bulkProcessPause'])) {
         //pause an ongoing bulk processing, it might be needed sometimes
         $this->prioQ->pauseBulk();
     }
     if (isset($_POST["bulkProcess"])) {
         //set the thumbnails option
         if (isset($_POST['thumbnails'])) {
             update_option('wp-short-process_thumbnails', 1);
         } else {
             update_option('wp-short-process_thumbnails', 0);
         }
         $this->prioQ->startBulk();
         self::log("BULK:  Start:  " . $this->prioQ->getStartBulkId() . ", stop: " . $this->prioQ->getStopBulkId() . " PrioQ: " . json_encode($this->prioQ->get()));
     }
     //end bulk process  was clicked
     if (isset($_POST["bulkProcessResume"])) {
         $this->prioQ->resumeBulk();
     }
     //resume was clicked
     //figure out all the files that could be processed
     $qry = "SELECT count(*) FilesToBeProcessed FROM " . $wpdb->prefix . "postmeta\n        WHERE meta_key = '_wp_attached_file' ";
     $allFiles = $wpdb->get_results($qry);
     //figure out the files that are left to be processed
     $qry_left = "SELECT count(*) FilesLeftToBeProcessed FROM " . $wpdb->prefix . "postmeta\n        WHERE meta_key = '_wp_attached_file' AND post_id <= " . $this->prioQ->getStartBulkId();
     $filesLeft = $wpdb->get_results($qry_left);
     if ($filesLeft[0]->FilesLeftToBeProcessed > 0 && $this->prioQ->bulkRunning()) {
         $msg = $this->bulkProgressMessage($this->prioQ->getDeltaBulkPercent(), $this->prioQ->getTimeRemaining());
         $this->view->displayBulkProcessingRunning($this->prioQ->getBulkPercent(), $msg);
         //            $imagesLeft = $filesLeft[0]->FilesLeftToBeProcessed;
         //            $totalImages = $allFiles[0]->FilesToBeProcessed;
         //            echo "<p>{$imagesLeft} out of {$totalImages} images left to process.</p>";
         //            echo ' <a class="button button-secondary" href="' . get_admin_url() .  'upload.php">Media Library</a> ';
     } else {
         if ($this->prioQ->bulkRan() && !$this->prioQ->bulkPaused()) {
             $this->prioQ->markBulkComplete();
         }
         //image count
         //$imageCount = $this->countAllProcessableFiles();
         //$imgProcessedCount = $this->countAllProcessedFiles();
         $imageOnlyThumbs = $quotaData['totalFiles'] - $quotaData['mainFiles'];
         $thumbsProcessedCount = self::getOpt('wp-short-pixel-thumbnail-count', 0);
         //amount of optimized thumbnails
         $under5PercentCount = self::getOpt('wp-short-pixel-files-under-5-percent', 0);
         //amount of under 5% optimized imgs.
         //average compression
         $averageCompression = self::getAverageCompression();
         $this->view->displayBulkProcessingForm($quotaData, $thumbsProcessedCount, $under5PercentCount, $this->prioQ->bulkRan(), $averageCompression, get_option('wp-short-pixel-fileCount'), self::formatBytes(get_option('wp-short-pixel-savedSpace')), $this->prioQ->bulkPaused() ? $this->prioQ->getBulkPercent() : false);
     }
 }