error() public méthode

Add error message to log
public error ( $type, $msg )
 /**
  * Process queue
  * Using lock file
  */
 function process()
 {
     global $db, $config, $phpEx, $phpbb_root_path, $user;
     $lock = new \phpbb\lock\flock($this->cache_file);
     $lock->acquire();
     // avoid races, check file existence once
     $have_cache_file = file_exists($this->cache_file);
     if (!$have_cache_file || $config['last_queue_run'] > time() - $config['queue_interval']) {
         if (!$have_cache_file) {
             set_config('last_queue_run', time(), true);
         }
         $lock->release();
         return;
     }
     set_config('last_queue_run', time(), true);
     include $this->cache_file;
     foreach ($this->queue_data as $object => $data_ary) {
         @set_time_limit(0);
         if (!isset($data_ary['package_size'])) {
             $data_ary['package_size'] = 0;
         }
         $package_size = $data_ary['package_size'];
         $num_items = !$package_size || sizeof($data_ary['data']) < $package_size ? sizeof($data_ary['data']) : $package_size;
         /*
         * This code is commented out because it causes problems on some web hosts.
         * The core problem is rather restrictive email sending limits.
         * This code is nly useful if you have no such restrictions from the
         * web host and the package size setting is wrong.
         
         // If the amount of emails to be sent is way more than package_size than we need to increase it to prevent backlogs...
         if (sizeof($data_ary['data']) > $package_size * 2.5)
         {
         	$num_items = sizeof($data_ary['data']);
         }
         */
         switch ($object) {
             case 'email':
                 // Delete the email queued objects if mailing is disabled
                 if (!$config['email_enable']) {
                     unset($this->queue_data['email']);
                     continue 2;
                 }
                 break;
             case 'jabber':
                 if (!$config['jab_enable']) {
                     unset($this->queue_data['jabber']);
                     continue 2;
                 }
                 include_once $phpbb_root_path . 'includes/functions_jabber.' . $phpEx;
                 $this->jabber = new jabber($config['jab_host'], $config['jab_port'], $config['jab_username'], htmlspecialchars_decode($config['jab_password']), $config['jab_use_ssl']);
                 if (!$this->jabber->connect()) {
                     $messenger = new messenger();
                     $messenger->error('JABBER', $user->lang['ERR_JAB_CONNECT']);
                     continue 2;
                 }
                 if (!$this->jabber->login()) {
                     $messenger = new messenger();
                     $messenger->error('JABBER', $user->lang['ERR_JAB_AUTH']);
                     continue 2;
                 }
                 break;
             default:
                 $lock->release();
                 return;
         }
         for ($i = 0; $i < $num_items; $i++) {
             // Make variables available...
             extract(array_shift($this->queue_data[$object]['data']));
             switch ($object) {
                 case 'email':
                     $err_msg = '';
                     $to = !$to ? 'undisclosed-recipients:;' : $to;
                     if ($config['smtp_delivery']) {
                         $result = smtpmail($addresses, mail_encode($subject), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $err_msg, $headers);
                     } else {
                         $result = phpbb_mail($to, $subject, $msg, $headers, $this->eol, $err_msg);
                     }
                     if (!$result) {
                         $messenger = new messenger();
                         $messenger->error('EMAIL', $err_msg);
                         continue 2;
                     }
                     break;
                 case 'jabber':
                     foreach ($addresses as $address) {
                         if ($this->jabber->send_message($address, $msg, $subject) === false) {
                             $messenger = new messenger();
                             $messenger->error('JABBER', $this->jabber->get_log());
                             continue 3;
                         }
                     }
                     break;
             }
         }
         // No more data for this object? Unset it
         if (!sizeof($this->queue_data[$object]['data'])) {
             unset($this->queue_data[$object]);
         }
         // Post-object processing
         switch ($object) {
             case 'jabber':
                 // Hang about a couple of secs to ensure the messages are
                 // handled, then disconnect
                 $this->jabber->disconnect();
                 break;
         }
     }
     if (!sizeof($this->queue_data)) {
         @unlink($this->cache_file);
     } else {
         if ($fp = @fopen($this->cache_file, 'wb')) {
             fwrite($fp, "<?php\nif (!defined('IN_PHPBB')) exit;\n\$this->queue_data = unserialize(" . var_export(serialize($this->queue_data), true) . ");\n\n?>");
             fclose($fp);
             phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE);
         }
     }
     $lock->release();
 }
Exemple #2
0
 /**
  * Process queue
  * Using lock file
  */
 function process()
 {
     global $db, $config, $phpEx, $phpbb_root_path, $user;
     set_config('last_queue_run', time(), true);
     // Delete stale lock file
     if (file_exists($this->cache_file . '.lock') && !file_exists($this->cache_file)) {
         @unlink($this->cache_file . '.lock');
         return;
     }
     if (!file_exists($this->cache_file) || file_exists($this->cache_file . '.lock') && filemtime($this->cache_file) > time() - $config['queue_interval']) {
         return;
     }
     $fp = @fopen($this->cache_file . '.lock', 'wb');
     fclose($fp);
     @chmod($this->cache_file . '.lock', 0777);
     include $this->cache_file;
     foreach ($this->queue_data as $object => $data_ary) {
         @set_time_limit(0);
         if (!isset($data_ary['package_size'])) {
             $data_ary['package_size'] = 0;
         }
         $package_size = $data_ary['package_size'];
         $num_items = !$package_size || sizeof($data_ary['data']) < $package_size ? sizeof($data_ary['data']) : $package_size;
         // If the amount of emails to be sent is way more than package_size than we need to increase it to prevent backlogs...
         if (sizeof($data_ary['data']) > $package_size * 2.5) {
             $num_items = sizeof($data_ary['data']);
         }
         switch ($object) {
             case 'email':
                 // Delete the email queued objects if mailing is disabled
                 if (!$config['email_enable']) {
                     unset($this->queue_data['email']);
                     continue 2;
                 }
                 break;
             case 'jabber':
                 if (!$config['jab_enable']) {
                     unset($this->queue_data['jabber']);
                     continue 2;
                 }
                 include_once $phpbb_root_path . 'includes/functions_jabber.' . $phpEx;
                 $this->jabber = new jabber($config['jab_host'], $config['jab_port'], $config['jab_username'], $config['jab_password'], $config['jab_use_ssl']);
                 if (!$this->jabber->connect()) {
                     messenger::error('JABBER', $user->lang['ERR_JAB_CONNECT']);
                     continue 2;
                 }
                 if (!$this->jabber->login()) {
                     messenger::error('JABBER', $user->lang['ERR_JAB_AUTH']);
                     continue 2;
                 }
                 break;
             default:
                 return;
         }
         for ($i = 0; $i < $num_items; $i++) {
             // Make variables available...
             extract(array_shift($this->queue_data[$object]['data']));
             switch ($object) {
                 case 'email':
                     $err_msg = '';
                     $to = !$to ? 'undisclosed-recipients:;' : $to;
                     if ($config['smtp_delivery']) {
                         $result = smtpmail($addresses, mail_encode($subject), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $err_msg, $headers);
                     } else {
                         ob_start();
                         $result = $config['email_function_name']($to, mail_encode($subject), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $headers);
                         $err_msg = ob_get_clean();
                     }
                     if (!$result) {
                         @unlink($this->cache_file . '.lock');
                         messenger::error('EMAIL', $err_msg);
                         continue 2;
                     }
                     break;
                 case 'jabber':
                     foreach ($addresses as $address) {
                         if ($this->jabber->send_message($address, $msg, $subject) === false) {
                             messenger::error('JABBER', $this->jabber->get_log());
                             continue 3;
                         }
                     }
                     break;
             }
         }
         // No more data for this object? Unset it
         if (!sizeof($this->queue_data[$object]['data'])) {
             unset($this->queue_data[$object]);
         }
         // Post-object processing
         switch ($object) {
             case 'jabber':
                 // Hang about a couple of secs to ensure the messages are
                 // handled, then disconnect
                 $this->jabber->disconnect();
                 break;
         }
     }
     if (!sizeof($this->queue_data)) {
         @unlink($this->cache_file);
     } else {
         if ($fp = @fopen($this->cache_file, 'wb')) {
             @flock($fp, LOCK_EX);
             fwrite($fp, "<?php\n\$this->queue_data = unserialize(" . var_export(serialize($this->queue_data), true) . ");\n\n?>");
             @flock($fp, LOCK_UN);
             fclose($fp);
             phpbb_chmod($this->cache_file, CHMOD_WRITE);
         }
     }
     @unlink($this->cache_file . '.lock');
 }
 function process()
 {
     global $site_file_root, $config;
     set_config('last_queue_run', time(), true);
     // Delete stale lock file
     if (file_exists($this->cache_file . '.lock') && !file_exists($this->cache_file)) {
         @unlink($this->cache_file . '.lock');
         return;
     }
     if (!file_exists($this->cache_file) || file_exists($this->cache_file . '.lock') && filemtime($this->cache_file) > time() - $config['queue_interval']) {
         return;
     }
     $fp = @fopen($this->cache_file . '.lock', 'wb');
     fclose($fp);
     include $this->cache_file;
     foreach ($this->queue_data as $object => $data_ary) {
         @set_time_limit(60);
         $package_size = $data_ary['package_size'];
         $num_items = sizeof($data_ary['data']) < $package_size ? sizeof($data_ary['data']) : $package_size;
         switch ($object) {
             case 'email':
                 // Delete the email queued objects if mailing is disabled
                 if (!$config['email_enable']) {
                     unset($this->queue_data['email']);
                     continue 2;
                 }
                 break;
             case 'jabber':
                 if (!$config['jab_enable']) {
                     unset($this->queue_data['jabber']);
                     continue 2;
                 }
                 require_once $site_file_root . 'includes/forums/functions_jabber.php';
                 $this->jabber = new jabber();
                 $this->jabber->server = $config['jab_host'];
                 $this->jabber->port = $config['jab_port'] ? $config['jab_port'] : 5222;
                 $this->jabber->username = $config['jab_username'];
                 $this->jabber->password = $config['jab_password'];
                 $this->jabber->resource = $config['jab_resource'] ? $config['jab_resource'] : '';
                 if (!$this->jabber->connect()) {
                     messenger::error('JABBER', 'Could not connect to Jabber server');
                     continue 2;
                 }
                 if (!$this->jabber->send_auth()) {
                     messenger::error('JABBER', 'Could not authorise on Jabber server');
                     continue 2;
                 }
                 $this->jabber->send_presence(NULL, NULL, 'online');
                 break;
             default:
                 return;
         }
         for ($i = 0; $i < $num_items; $i++) {
             extract(array_shift($this->queue_data[$object]['data']));
             switch ($object) {
                 case 'email':
                     $err_msg = '';
                     $to = !$to ? 'Undisclosed-Recipient:;' : $to;
                     $result = $config['smtp_delivery'] ? smtpmail($addresses, $subject, wordwrap($msg), $err_msg, $encoding, $headers) : @$config['email_function_name']($to, $subject, implode("\n", preg_split("/\r?\n/", wordwrap($msg))), $headers);
                     if (!$result) {
                         @unlink($this->cache_file . '.lock');
                         $message = 'Method: [ ' . ($config['smtp_delivery'] ? 'SMTP' : 'PHP') . ' ]<br /><br />' . $err_msg . '<br /><br /><u>CALLING PAGE</u><br /><br />' . (!empty($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF']);
                         messenger::error('MAIL', $message);
                         continue 3;
                     }
                     break;
                 case 'jabber':
                     foreach ($addresses as $address) {
                         $this->jabber->send_message($address, 'normal', NULL, array('body' => $msg));
                     }
                     break;
             }
         }
         // No more data for this object? Unset it
         if (!sizeof($this->queue_data[$object]['data'])) {
             unset($this->queue_data[$object]);
         }
         // Post-object processing
         switch ($object) {
             case 'jabber':
                 // Hang about a couple of secs to ensure the messages are
                 // handled, then disconnect
                 sleep(1);
                 $this->jabber->disconnect();
                 break;
         }
     }
     if (!sizeof($this->queue_data)) {
         @unlink($this->cache_file);
     } else {
         $file = '<?php $this->queue_data=' . $this->format_array($this->queue_data) . '; ?>';
         if ($fp = @fopen($this->cache_file, 'w')) {
             @flock($fp, LOCK_EX);
             fwrite($fp, $file);
             @flock($fp, LOCK_UN);
             fclose($fp);
         }
     }
     @unlink($this->cache_file . '.lock');
 }