Inheritance: extends Object
示例#1
0
 /**
  * Execute the action
  * We will build the classname, require the class and call the execute method.
  */
 protected function execute()
 {
     if (extension_loaded('newrelic')) {
         newrelic_background_job();
     }
     $this->loadConfig();
     // build action-class-name
     $actionClass = 'Backend\\Modules\\' . $this->getModule() . '\\Cronjobs\\' . $this->getAction();
     if ($this->getModule() == 'Core') {
         $actionClass = 'Backend\\Core\\Cronjobs\\' . $this->getAction();
     }
     // validate if class exists (aka has correct name)
     if (!class_exists($actionClass)) {
         // set correct headers
         \SpoonHTTP::setHeadersByCode(500);
         // throw exception
         throw new Exception('The cronjobfile is present, but the classname should be: ' . $actionClass . '.');
     }
     // create action-object
     $this->cronjob = new $actionClass($this->getKernel());
     $this->cronjob->setModule($this->getModule());
     $this->cronjob->setAction($this->getAction());
     if (extension_loaded('newrelic')) {
         newrelic_name_transaction('cronjob::' . $this->getModule() . '::' . $this->getAction());
     }
 }
示例#2
0
 /**
  * Execute the action
  * We will build the classname, require the class and call the execute method.
  */
 protected function execute()
 {
     if (extension_loaded('newrelic')) {
         newrelic_background_job();
     }
     $this->loadConfig();
     // build action-class-name
     $actionClass = 'Backend\\Modules\\' . $this->getModule() . '\\Cronjobs\\' . $this->getAction();
     if ($this->getModule() == 'Core') {
         $actionClass = 'Backend\\Core\\Cronjobs\\' . $this->getAction();
     }
     // validate if class exists (aka has correct name)
     if (!class_exists($actionClass)) {
         // set correct headers
         header('HTTP/1.1 500 Internal Server Error');
         // throw exception
         throw new Exception('The cronjobfile ' . $actionClass . ' could not be found.');
     }
     // create action-object
     $this->cronjob = new $actionClass($this->getKernel());
     $this->cronjob->setModule($this->getModule());
     $this->cronjob->setAction($this->getAction());
     if (extension_loaded('newrelic')) {
         newrelic_name_transaction('cronjob::' . $this->getModule() . '::' . $this->getAction());
     }
 }
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // Get api key
     $this->apiKey = BackendModel::getModuleSetting($this->getModule(), 'api_key', null);
     // Get uncompressed images list
     $this->images = BackendCompressionModel::getImagesFromFolders();
     if (!empty($this->images)) {
         // Compress each image from each folder
         $output = 'Compressing ' . count($this->images) . ' images...' . "<br />\r\n";
         BackendCompressionModel::writeToCacheFile($output, true);
         foreach ($this->images as $image) {
             $tinyPNGApi = new TinyPNGApi($this->apiKey);
             // Shrink the image and check if succesful
             if ($tinyPNGApi->shrink($image['full_path'])) {
                 // Check if the file was successfully downloaded.
                 if ($tinyPNGApi->download($image['full_path'])) {
                     $output = 'Compression succesful for image ' . $image['filename'] . '. Saved ' . number_format($tinyPNGApi->getSavingSize() / 1024, 2) . ' KB' . ' bytes. (' . $tinyPNGApi->getSavingPercentage() . '%)';
                     BackendCompressionModel::writeToCacheFile($output);
                     // Save to db
                     $imageInfo = array('filename' => $image['filename'], 'path' => $image['full_path'], 'original_size' => $tinyPNGApi->getInputSize(), 'compressed_size' => $tinyPNGApi->getOutputSize(), 'saved_bytes' => $tinyPNGApi->getSavingSize(), 'saved_percentage' => $tinyPNGApi->getSavingPercentage(), 'checksum_hash' => sha1_file($image['full_path']), 'compressed_on' => BackendModel::getUTCDate());
                     BackendCompressionModel::insertImageHistory($imageInfo, $image['file_compressed_before']);
                 }
             } else {
                 BackendCompressionModel::writeToCacheFile($tinyPNGApi->getErrorMessage());
             }
         }
         BackendCompressionModel::writeToCacheFile("...Done!");
     } else {
         BackendCompressionModel::writeToCacheFile('There are no images that can be compressed.', true);
     }
     // Print the output for debug purposes
     $output = BackendCompressionModel::readCacheFile();
     print $output;
 }
示例#4
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     //--Get the mailings which are ready to send
     $mails = BackendMailengineModel::getWaitingMailings();
     if (!empty($mails)) {
         //--Loop the mails
         foreach ($mails as $mail) {
             //--Get mailer-email to send the mail to
             $arrFrom = BackendModel::getModuleSetting('Core', 'mailer_from');
             //--Create variables array
             $variables = array();
             $variables['sentOn'] = time();
             $variables['dateFormatLong'] = BackendModel::getModuleSetting('Core', 'date_format_long') . " " . BackendModel::getModuleSetting('Core', 'time_format');
             $variables['subject'] = $mail['subject'];
             //--Send start mail
             /* $message = \Common\Mailer\Message::newInstance(
                    'Mailing started "' . $mail['subject'] . '"'
                )
                    ->setFrom(array($arrFrom['email'] => $arrFrom['name']))
                    ->setTo(array($arrFrom['email']))
                    ->parseHtml(
                        BACKEND_MODULES_PATH . '/Modules/Mailengine/Layout/Templates/Mails/MailingStart.tpl',
                        $variables
                    )
                ;
                $this->get('mailer')->send($message);*/
             //				$this->get('mailer')->addEmail('Mailing started "' . $mail['subject'] . '"', BACKEND_PATH . '/Modules/Mailengine/Layout/Templates/Mails/MailingStart.tpl', $variables, $arrFrom["email"], $arrFrom["name"]);
             //--Insert mail in stats
             $data = array();
             $data['id'] = $mail['id'];
             $data['mail_id'] = $mail['mail_id'];
             $data['domain'] = $mail['domain'];
             $data['subject'] = $mail['subject'];
             $data['text'] = $mail['text'];
             $data['start_time'] = $mail['start_time'];
             $data['end_time'] = $mail['end_time'];
             $data['from_name'] = $mail['from_name'];
             $data['from_email'] = $mail['from_email'];
             $data['reply_name'] = $mail['reply_name'];
             $data['reply_email'] = $mail['reply_email'];
             BackendMailengineModel::insertMailToStats($data);
             $mail['from_name'] = html_entity_decode($mail['from_name']);
             $mail['reply_name'] = html_entity_decode($mail['reply_name']);
             //--Update status
             BackendMailengineModel::updateStatusMailing($mail['id'], array('status' => 'busy'));
             //--Get the users for the mailing
             $users = BackendMailengineModel::getUsersForWaitingMail($mail['id']);
             if (!empty($users)) {
                 $count = 0;
                 //--Loop the users
                 foreach ($users as $user) {
                     //--Translate the text and subject with the user-vars
                     $text = BackendMailengineModel::translateUserVars($mail['text'], $user);
                     $subject = BackendMailengineModel::translateUserVars($mail['subject'], $user);
                     //--Send the mail
                     if (BackendMailengineModel::sendMail(html_entity_decode($subject), $text, $user['email'], $user['name'], $mail)) {
                         $data = array();
                         $data['send_id'] = $mail['id'];
                         $data['user_id'] = $user['id'];
                         //--Save the send-data for the mails
                         BackendMailengineModel::insertMailUsers($data);
                     }
                     //--Add count
                     $count++;
                     //--Let the script sleep for an instant after sending x-numbers of mails
                     if ($count % 50 == 0) {
                         sleep(5);
                         set_time_limit(120);
                     }
                 }
                 //--Update status
                 BackendMailengineModel::updateStatusMailing($mail['id'], array('status' => 'finished', 'end_time' => BackendModel::getUTCDate()));
                 //--Create variables array
                 $variables = array();
                 $variables['sentOn'] = time();
                 $variables['dateFormatLong'] = BackendModel::getModuleSetting('Core', 'date_format_long') . " " . BackendModel::getModuleSetting('Core', 'time_format');
                 $variables['subject'] = $mail['subject'];
                 $variables['users'] = count($users);
                 /*$message = \Common\Mailer\Message::newInstance(
                       'Mailing ended "' . $mail['subject'] . '"'
                   )
                       ->setFrom(array($arrFrom['email'] => $arrFrom['name']))
                       ->setTo(array($arrFrom['email']))
                       ->parseHtml(
                           BACKEND_MODULES_PATH . '/Modules/Mailengine/Layout/Templates/Mails/MailingEnd.tpl',
                           $variables
                       )
                   ;
                   $this->get('mailer')->send($message);*/
                 //--Send start mail
                 //					$this->get('mailer')->addEmail('Mailing ended "' . $mail['subject'] . '"', BACKEND_PATH . '/Modules/Mailengine/Layout/Templates/Mails/MailingEnd.tpl', $variables, $arrFrom["email"], $arrFrom["name"]);
             }
         }
     }
 }