/** * * @param string $addressString * @param string $fullInfo if FALSE there is latitude and longitude returned only * @return array */ public function lookupGeoCode($addressString, $fullInfo = FALSE) { $request = "https://maps.googleapis.com/maps/api/geocode/json?address=" . rawurlencode($addressString) . "&key="; $result = array(); $time = microtime(TRUE); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $request); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); $response = curl_exec($curl); curl_close($curl); $requestTime = microtime(TRUE) - $time; if ($requestTime > 2) { tx_rnbase_util_Logger::notice('Long request time for Google address lookup ', 'rn_base', array('uri' => $request, 'time' => $requestTime)); } if ($response) { $response = json_decode($response, true); if ($response['status'] == 'OK') { if (!$fullInfo) { $result = reset($response['results']); $result = $result['geometry']['location']; } else { $result = $response; } } elseif ($response['status'] == 'OVER_QUERY_LIMIT') { throw new Exception($response['error_message']); } } return $result; }
function test_logger() { if (tx_rnbase_util_Extensions::isLoaded('devlog')) { $minLog = tx_rnbase_configurations::getExtensionCfgValue('devlog', 'minLogLevel'); if ($minLog === FALSE) { $ret = tx_rnbase_util_Logger::isNoticeEnabled(); $this->assertTrue($ret, 'Notice funktioniert nicht.'); } if ($minLog == 1) { $ret = tx_rnbase_util_Logger::isNoticeEnabled(); $this->assertTrue($ret, 'Notice funktioniert nicht.'); $ret = tx_rnbase_util_Logger::isWarningEnabled(); $this->assertTrue($ret, 'Warning funktioniert nicht.'); $ret = tx_rnbase_util_Logger::isFatalEnabled(); $this->assertTrue($ret, 'Fatal funktioniert nicht.'); $ret = tx_rnbase_util_Logger::isInfoEnabled(); $this->assertFalse($ret, 'Info funktioniert nicht.'); $ret = tx_rnbase_util_Logger::isDebugEnabled(); $this->assertFalse($ret, 'Debug funktioniert nicht.'); } if ($minLog == 3) { $ret = tx_rnbase_util_Logger::isNoticeEnabled(); $this->assertFalse($ret, 'Notice funktioniert nicht.'); $ret = tx_rnbase_util_Logger::isWarningEnabled(); $this->assertFalse($ret, 'Warning funktioniert nicht.'); $ret = tx_rnbase_util_Logger::isFatalEnabled(); $this->assertTrue($ret, 'Fatal funktioniert nicht.'); $ret = tx_rnbase_util_Logger::isInfoEnabled(); $this->assertFalse($ret, 'Info funktioniert nicht.'); $ret = tx_rnbase_util_Logger::isDebugEnabled(); $this->assertFalse($ret, 'Debug funktioniert nicht.'); } } }
/** * Validiert einen PLZ-String für ein Land. * @param tx_mklib_interface_IZipCountry $land * @param string $zip * @return boolean */ public static function validate(tx_mklib_interface_IZipCountry $country, $zip) { $result = true; switch ($country->getZipRule()) { case 0: // no rule set $result = true; tx_rnbase::load('tx_rnbase_util_Logger'); if (tx_rnbase_util_Logger::isNoticeEnabled()) { tx_rnbase_util_Logger::notice('No zip rule for country defined.', 'mklib', array('zip' => $zip, 'getISO2' => $country->getISO2(), 'getZipLength' => $country->getZipLength(), 'getZipRule' => $country->getZipRule())); } break; case 1: // maximum length without gaps $result = self::validateMaxLengthWG($country, $zip); break; case 2: // maximum length numerical without gaps $result = self::validateMaxLengthNumWG($country, $zip); break; case 3: // exact length without gaps $result = self::validateLengthWG($country, $zip); break; case 4: // exact length numerical without gaps $result = self::validateLengthNumWG($country, $zip); break; case 5: // maximum length with gaps $result = self::validateMaxLength($country, $zip); break; case 6: // maximum length numerical with gaps $result = self::validateMaxLengthNum($country, $zip); break; case 7: // exact length with gaps $result = self::validateLength($country, $zip); break; case 8: // exact length numerical with gaps $result = self::validateLengthNum($country, $zip); break; case 9: // special rules $result = self::validateSpecial($country, $zip); break; default: $result = false; break; } return $result; }
/** * Stops PHP execution : die() if some critical error appeared * This method is taken from the great ameos_formidable extension. * * @param string $msg: the error message * @return void */ public static function mayday($msg, $extKey = '') { tx_rnbase::load('tx_rnbase_util_Logger'); tx_rnbase::load('tx_rnbase_util_Debug'); tx_rnbase_util_Logger::fatal($msg, $extKey ? $extKey : 'rn_base'); $aTrace = debug_backtrace(); $aLocation = array_shift($aTrace); $aTrace1 = array_shift($aTrace); $aTrace2 = array_shift($aTrace); $aTrace3 = array_shift($aTrace); $aTrace4 = array_shift($aTrace); $aDebug = array(); $aDebug[] = '<h2 id="backtracetitle">Call stack</h2>'; $aDebug[] = '<div class="backtrace">'; $aDebug[] = '<span class="notice"><b>Call 0: </b>' . str_replace(PATH_site, '/', $aLocation['file']) . ':' . $aLocation['line'] . ' | <b>' . $aTrace1['class'] . $aTrace1['type'] . $aTrace1['function'] . '</b></span><br/>With parameters: ' . (!empty($aTrace1['args']) ? self::viewMixed($aTrace1['args']) : ' no parameters'); $aDebug[] = '<hr/>'; $aDebug[] = '<span class="notice"><b>Call -1: </b>' . str_replace(PATH_site, '/', $aTrace1['file']) . ':' . $aTrace1['line'] . ' | <b>' . $aTrace2['class'] . $aTrace2['type'] . $aTrace2['function'] . '</b></span><br />With parameters: ' . (!empty($aTrace2['args']) ? self::viewMixed($aTrace2['args']) : ' no parameters'); $aDebug[] = '<hr/>'; $aDebug[] = '<span class="notice"><b>Call -2: </b>' . str_replace(PATH_site, '/', $aTrace2['file']) . ':' . $aTrace2['line'] . ' | <b>' . $aTrace3['class'] . $aTrace3['type'] . $aTrace3['function'] . '</b></span><br />With parameters: ' . (!empty($aTrace3['args']) ? self::viewMixed($aTrace3['args']) : ' no parameters'); $aDebug[] = '<hr/>'; $aDebug[] = '<span class="notice"><b>Call -3: </b>' . str_replace(PATH_site, '/', $aTrace3['file']) . ':' . $aTrace3['line'] . ' | <b>' . $aTrace4['class'] . $aTrace4['type'] . $aTrace4['function'] . '</b></span><br />With parameters: ' . (!empty($aTrace4['args']) ? self::viewMixed($aTrace4['args']) : ' no parameters'); $aDebug[] = '<hr/>'; if ($debugTrail = tx_rnbase_util_Debug::getDebugTrail()) { $aDebug[] = '<span class="notice">' . $debugTrail . '</span>'; $aDebug[] = '<hr/>'; } $aDebug[] = '</div>'; if (intval(tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'forceException4Mayday'))) { throw tx_rnbase::makeInstance('tx_rnbase_util_Exception', $msg, 0, array('Info' => $aDebug)); } $aDebug[] = '<br/>'; $sContent = '<h1 id="title">Mayday</h1>'; $sContent .= '<div id="errormessage">' . $msg . '</div>'; $sContent .= '<hr />'; $verbose = intval(tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'verboseMayday')); if ($verbose) { $sContent .= implode('', $aDebug); } $sPage = <<<MAYDAYPAGE <!DOCTYPE html \tPUBLIC '-//W3C//DTD XHTML 1.1//EN' \t'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'> \t<head> \t\t<title>{$extKey}::Mayday</title> \t\t<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> \t\t<meta name="robots" content="noindex, nofollow" /> \t\t<style type="text/css"> \t\t\t#title { \t\t\t\tcolor: red; \t\t\t\tfont-family: Verdana; \t\t\t} \t\t\t#errormessage { \t\t\t\tborder: 2px solid red; \t\t\t\tpadding: 10px; \t\t\t\tcolor: white; \t\t\t\tbackground-color: red; \t\t\t\tfont-family: Verdana; \t\t\t\tfont-size: 12px; \t\t\t} \t\t\t.notice { \t\t\t\tfont-family: Verdana; \t\t\t\tfont-size: 9px; \t\t\t\tfont-style: italic; \t\t\t} \t\t\t#backtracetitle { \t\t\t} \t\t\t.backtrace { \t\t\t\tbackground-color: #FFFFCC; \t\t\t} \t\t\tHR { \t\t\t\tborder: 1px solid silver; \t\t\t} \t\t</style> \t</head> \t<body> \t\t{$sContent} \t</body> </html> MAYDAYPAGE; $dieOnMayday = intval(tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'dieOnMayday')); if ($dieOnMayday) { die($sPage); } else { echo $sPage; } }
/** * Function executed from the Scheduler. * * @return boolean Returns true on successful execution, false on error */ public function execute() { /* beispiel für das logging array. $devLog = array('message' => '', 'extKey' => 'mklib', 'dataVar' => FALSE); $devLog = array( tx_rnbase_util_Logger::LOGLEVEL_DEBUG => $devLog, tx_rnbase_util_Logger::LOGLEVEL_INFO => $devLog, tx_rnbase_util_Logger::LOGLEVEL_NOTICE => $devLog, tx_rnbase_util_Logger::LOGLEVEL_WARN => $devLog, tx_rnbase_util_Logger::LOGLEVEL_FATAL => $devLog ); */ $devLog = array(); $options = $this->getOptions(); $startTimeInMilliseconds = t3lib_div::milliseconds(); $memoryUsageAtStart = memory_get_usage(); tx_rnbase_util_Logger::info('[' . get_class($this) . ']: Scheduler starts', $this->getExtKey()); try { $message = $this->executeTask($options, $devLog); $this->setLastRunTime(); // devlog if (t3lib_extMgm::isLoaded('devlog')) { if (empty($devLog) || isset($devLog[tx_rnbase_util_Logger::LOGLEVEL_INFO]) && empty($devLog[tx_rnbase_util_Logger::LOGLEVEL_INFO]['message'])) { $devLog[tx_rnbase_util_Logger::LOGLEVEL_INFO]['message'] = $message; } foreach ($devLog as $logLevel => $logData) { if (empty($logData['message'])) { continue; } t3lib_div::devLog('[' . get_class($this) . ']: ' . $logData['message'], isset($logData['extKey']) ? $logData['extKey'] : $this->getExtKey(), $logLevel, isset($logData['dataVar']) ? $logData['dataVar'] : FALSE); } } } catch (Exception $exception) { $dataVar = array('errorcode' => $exception->getCode(), 'errormsg' => $exception->getMessage(), 'trace' => $exception->getTraceAsString(), 'options' => $options, 'devlog' => $devLog); if ($exception instanceof tx_rnbase_util_Exception) { $dataVar['exception_data'] = $exception->getAdditional(FALSE); } if (tx_rnbase_util_Logger::isFatalEnabled()) { tx_rnbase_util_Logger::fatal('Task [' . get_class($this) . '] failed.' . ' Error(' . $exception->getCode() . '):' . $exception->getMessage(), $this->getExtKey(), $dataVar); } // Exception Mail an die Entwicker senden $mail = tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'sendEmailOnException'); if (!empty($mail)) { $this->sendErrorMail($mail, tx_rnbase::makeInstance('tx_rnbase_util_Exception', get_class($exception) . ': ' . $exception->getMessage(), $exception->getCode(), $dataVar, $exception)); } // Wir geben die Exception weiter, // damit der Scheduler eine entsprechende Meldung ausgeben kann. throw $exception; } $memoryUsageAtEnd = memory_get_usage(); tx_rnbase_util_Logger::info('[' . get_class($this) . ']: Scheduler ends successful ', $this->getExtKey(), array('Execution Time' => t3lib_div::milliseconds() - $startTimeInMilliseconds . ' ms', 'Memory Start' => $memoryUsageAtStart . ' Bytes', 'Memory End' => $memoryUsageAtEnd . ' Bytes', 'Memory Consumed' => $memoryUsageAtEnd - $memoryUsageAtStart . ' Bytes')); return true; }
/** * Create a zip-archive from a list of files * * @param array $files * @param string $destination full path of zip file * @param boolean $overwrite * @return boolean TRUE, if zip file was created */ public static function makeZipFile($files = array(), $destination = '', $overwrite = FALSE) { if (!extension_loaded('zip')) { tx_rnbase::load('tx_rnbase_util_Logger'); tx_rnbase_util_Logger::warn('PHP zip extension not loaded!', 'rn_base'); return false; } //if the zip file already exists and overwrite is FALSE, return FALSE if (file_exists($destination) && !$overwrite) { return FALSE; } //vars $valid_files = array(); //if files were passed in... if (!is_array($files)) { return FALSE; } foreach ($files as $file) { if (file_exists($file)) { $valid_files[] = $file; } } //if we have good files... if (!count($valid_files)) { return FALSE; } //create the archive $zip = new ZipArchive(); if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== TRUE) { return FALSE; } //add the files foreach ($valid_files as $file) { $filename = basename($file); $zip->addFile($file, iconv('UTF-8', 'IBM850', $filename)); } //close the zip -- done! $zip->close(); //check to make sure the file exists return file_exists($destination); }
/** * * @return integer the number of recipients who were accepted for delivery */ public function send() { /* @var $mail TYPO3\CMS\Core\Mail\MailMessage */ $mail = tx_rnbase::makeInstance(tx_rnbase_util_Typo3Classes::getMailMessageClass()); $mail->setFrom($this->from, $this->fromName); foreach ($this->to as $email => $name) { $mail->addTo($email, $name); } $mail->setSubject($this->subject); if ($this->replyTo) { $mail->addReplyTo($this->replyTo, $this->replyToName); } // Or set it after like this if ($this->htmlPart) { $mail->setBody($this->htmlPart, 'text/html'); } // Add alternative parts with addPart() if ($this->textPart) { $mail->addPart($this->textPart, 'text/plain'); } if (!empty($this->attachments)) { foreach ($this->attachments as $attachment) { if (!$mail->attach(Swift_Attachment::fromPath($attachment['src']))) { tx_rnbase_util_Logger::warn('Adding attachment failed!', 'rn_base', array('subject' => $mail->subject, 'to' => $this->toAsString, 'attachment' => $attachment)); } } } return $this->sendMessage($mail); }
/** * Optionen aus der TS-Config setzen * * @param array $options * @param tx_rnbase_configurations $configurations * @param string $confId Id der TS-Config z.B. myview.options. */ static function setConfigOptions(&$options, $configurations, $confId) { $cfgOptions = $configurations->get($confId); if (is_array($cfgOptions)) { foreach ($cfgOptions as $option => $cfg) { // Auf einfache Option ohne Klammerung prüfen if (substr($option, -1) != '.') { $options[$option] = $cfg; continue; } // Ohne Angaben nix zu tun if (!is_array($cfg)) { continue; } // Zuerst den Namen der Option holen. Dieser ist immer klein // Beispiel orderby, count... $optionName = strtolower(substr($option, 0, strlen($option) - 1)); // Hier jetzt die Implementierung für orderby. da gibt es mehr // Angaben als z.B. bei count. while (list($table, $data) = each($cfg)) { /* * was, wenn im ts etwas wie folgt angegeben ist? * options.limit = 5 * options.limit.override = 10 * das führt zu php offset fehlern, * da limit bereits 5 ist und deshalb kein array werden kann. * der code sieht aktuell nur eines der beiden methoden vor. * entweder eine zuweisung als array oder skalaren Wert. * Wir ignorieren daher bereits existierende skalare Werte * und schreiben eine Log, es sei denn es sind bekannte Werte * wie override oder force, dann wird direkt ignoriert */ if (isset($options[$optionName]) && !is_array($options[$optionName])) { if (!in_array($optionName, array('override', 'force'))) { tx_rnbase::load('tx_rnbase_util_Logger'); tx_rnbase_util_Logger::warn('Invalid configuration for config option "' . $optionName . '".', 'rn_base', array('option_name' => $optionName, 'cfg' => $cfg)); } continue; } $tableAlias = strtoupper(substr($table, 0, strlen($table) - 1)); if (is_array($data) && $option == 'searchdef.') { foreach ($data as $col => $value) { $options[$optionName][strtolower($tableAlias)][substr($col, 0, strlen($col) - 1)] = $value; } } elseif (is_array($data)) { foreach ($data as $col => $value) { $options[$optionName][$tableAlias . '.' . $col] = $value; } } else { // Ohne Array erfolgt direkt eine Ausgabe (Beispiel RAND = 1) $options[$optionName][$table] = $data; } } } } }
/** * Do the magic and publish all new messages thu the transport. * * @return bool Returns TRUE on successful execution, FALSE on error */ public function execute() { $failures = $successes = array(); $transport = $this->getTransport(); // initialize the transport $transport->initialize($this->getOptions()); /* @var $message \DMK\Mklog\Domain\Model\DevlogEntryModel */ foreach ($this->findMessages() as $message) { try { $transport->publish($message); // mark entry as send for current transport $this->markAsTransported($message); $successes[$message->getUid()] = ''; } catch (\Exception $e) { $failures[$message->getUid()] = $e->getMessage(); } } // shutdown the transport $transport->shutdown(); \tx_rnbase::load('tx_rnbase_util_Logger'); $success = empty($failures); $msg = sprintf('WatchDog %1$s has %2$d messages send and %3$d failures.', $this->getTransportId(), count($successes), count($failures)); \tx_rnbase_util_Logger::devLog($msg, 'mklog', $success ? \tx_rnbase_util_Logger::LOGLEVEL_DEBUG : \tx_rnbase_util_Logger::LOGLEVEL_WARN, array('transport' => $this->getTransportId(), 'successes' => $successes, 'failures' => $failures)); // create a flash message for the beuser \tx_rnbase::load('tx_rnbase_util_TYPO3'); if (\tx_rnbase_util_TYPO3::getBEUserUID()) { \tx_rnbase::load('tx_rnbase_util_Misc'); \tx_rnbase_util_Misc::addFlashMessage($msg, 'MK LOGGER WatchDog', $success ? 0 : 2, false); } return $success; }
/** * Function executed from the Scheduler. * Sends an email * * @return boolean */ public function execute() { $success = TRUE; $taskId = $this->taskUid; tx_rnbase::load('tx_rnbase_util_Misc'); try { $lastRun = $this->getLastRunTime($taskId); /* @var $srv tx_mklog_srv_WatchDog */ $srv = tx_rnbase_util_Misc::getService('mklog', 'WatchDog'); $filters = array(); $options = array(); $options['minimalSeverity'] = $this->getMinimalSeverity(); $options['forceSummaryMail'] = $this->getForceSummaryMail(); $options['includeDataVar'] = $this->getIncludeDataVar(); //damit jede Nachricht nur einmal kommt, auch wenn sie mehrmals vorhanden ist if ($this->getGroupEntries()) { $options['groupby'] = Tx_Mklog_Utility_Devlog::getMessageFieldName() . ',extkey'; // wir wollen aber wissen wie oft jede Nachricht vorhanden ist $options['count'] = TRUE; } $srv->triggerMails($this->getEmailReceiver(), $lastRun, $filters, $options); $this->updateLastRunTime($taskId); } catch (Exception $e) { tx_rnbase_util_Logger::fatal('WatchDog failed!', 'mklog', array('Exception' => $e->getMessage())); $success = FALSE; } return $success; }
/** * * @param array * @return \TYPO3\CMS\Core\Database\DatabaseConnection|tx_rnbase_util_db_IDatabase */ public function getDatabaseConnection($options = NULL) { if (is_array($options) && !empty($options['db'])) { $dbConfig =& $options['db']; if (is_string($dbConfig)) { $db = $this->getDatabase($dbConfig); } elseif (is_object($dbConfig)) { $db = $dbConfig; } if (!$db instanceof tx_rnbase_util_db_IDatabase) { tx_rnbase::load('tx_rnbase_util_Logger'); tx_rnbase_util_Logger::warn('The db "' . get_class($db) . '" has to implement' . ' the tx_rnbase_util_db_IDatabase interface', 'rn_base'); $db = NULL; } } return is_object($db) ? $db : $GLOBALS['TYPO3_DB']; }
/** * Interne Verarbeitung der Exception * @param Exception $e * @param tx_rnbase_Configurations $configurations */ private function handleException($actionName, Exception $e, $configurations) { $exceptionHandlerClass = tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'exceptionHandler'); $defaultExceptionHandlerClass = 'tx_rnbase_exception_Handler'; if (!$exceptionHandlerClass) { $exceptionHandlerClass = $defaultExceptionHandlerClass; } $exceptionHandler = tx_rnbase::makeInstance($exceptionHandlerClass); if (!$exceptionHandler instanceof tx_rnbase_exception_IHandler) { $exceptionHandler = tx_rnbase::makeInstance($defaultExceptionHandlerClass); tx_rnbase::load('tx_rnbase_util_Logger'); tx_rnbase_util_Logger::fatal("the configured error handler ({$exceptionHandlerClass}) does not implement the tx_rnbase_exception_IHandler interface", 'rn_base'); } return $exceptionHandler->handleException($actionName, $e, $configurations); }
/** * creates a lock file and stores the current time. * * @return boolean */ private function createLockFile() { $fileName = $this->getFile(); if (!is_dir(dirname($fileName))) { tx_rnbase_util_Files::mkdir_deep(dirname($fileName)); } file_put_contents($fileName, time()); if (!is_readable($fileName)) { tx_rnbase::load('tx_rnbase_util_Logger'); tx_rnbase_util_Logger::warn('Lock file could not be created for "' . $this->getName() . '" process!', 'rn_base', array('process_name' => $this->getName(), 'life_time' => $this->getLifeTime(), 'lock_file' => $fileName)); return FALSE; } return TRUE; }
/** * chechs, if the exception was allready thrown in the stack. * returns TRUE, if the exception was allready thrown. * * die recursion können wir an dieser stelle nicht über den backtrace prüfen. * bei ungecachten ausgaben wird bei typo3 mit int_script gearbeidet, * wodurch der stack auch bei mehrfacher rekursion immer gleich ist, * also die methode nur ein mal auftaucht. * * @param string $actionName * @param Exception $e * @param tx_rnbase_configurations $configurations * @return boolean */ private function checkExceptionRecursion($action, Exception $e, tx_rnbase_configurations $configurations, $type = 'error') { static $calls = 0, $trace = array(); // konfiguration für die maximale anzahl an durchläufen holen. $maxCalls = $configurations->getInt('recursionCheck.maxCalls'); $maxCalls = $maxCalls ? $maxCalls : 50; $maxThrows = $configurations->getInt('recursionCheck.maxThrows'); $maxThrows = $maxThrows ? $maxThrows : 1; // bei mehr als 50 exception calls, müssen wir davon ausgehen, // das ein kritischer fehler vorliegt if (++$calls > $maxCalls) { tx_rnbase_util_Logger::fatal('Too much recursion in "' . get_class($this) . '"' . ' That should not have happened.' . ' It looks as if there is a problem with a faulty configuration.', 'rn_base'); return TRUE; } // else // ansonsten setzen wir eine art stack aus action, errorcode und config zusammen. $code = $e->getCode(); // das typoscript wir bei jedem plugin aufruf neu generiert // und unterscheidet sich demnach. // wenn es zu einer rekursion kommt, ist das ts allerdings immer gleich! // (abgesehen von unaufgelösten referenzen) $configKey = md5(serialize($configurations->getConfigArray())); if (empty($trace[$type])) { $trace[$type] = array(); } if (empty($trace[$type][$action])) { $trace[$type][$action] = array(); } if (empty($trace[$type][$action][$code])) { $trace[$type][$action][$code] = array(); } if (empty($trace[$type][$action][$code][$configKey])) { $trace[$type][$action][$code][$configKey] = 0; } $trace[$type][$action][$code][$configKey]++; if (isset($trace[$type][$action][$code][$configKey]) && $trace[$type][$action][$code][$configKey] > $maxThrows) { return TRUE; } return FALSE; }
/** * Logs DB changes * * @TODO: t3users log nutzen, wenn installiert! tx_t3users_util_ServiceRegistry::getLoggingService(); * * @param string $msg * @param string $tablename * @param string $where * @param mixed $values */ private static function log($msg, $tablename, $where = false, $values = false) { if (!self::isLog($tablename)) { return false; } // else // daten sammeln $data = array(); $data['fe_user'] = isset($GLOBALS['TSFE']->fe_user->user['uid']) ? $GLOBALS['TSFE']->fe_user->user['uid'] : 'none'; $data['be_user'] = array_key_exists('BE_USER', $GLOBALS) && is_object($GLOBALS['BE_USER']) ? $GLOBALS['BE_USER']->user['uid'] : 'none'; $data['tablename'] = $tablename; if ($where) { $data['where'] = $where; } if ($values) { $data['values'] = $values; } // backtrace Konfigurierbar machen? tx_rnbase::load('tx_mklib_util_Logger'); $data['debug_backtrace'] = tx_mklib_util_Logger::getDebugBacktrace(); // wurde auf hidden gesetzt? $disabled = tx_mklib_util_TCA::getEnableColumn($tablename, 'disabled', 'hidden'); if ($values && isset($values[$disabled]) && $values[$disabled]) { $msg .= '->disabled'; } // wurde gelöscht? $delete = tx_mklib_util_TCA::getEnableColumn($tablename, 'delete', 'deleted'); if ($values && isset($values[$delete]) && $values[$delete]) { $msg .= '->delete'; } // tabellenname ergänzen $msg .= '(' . $tablename . ')'; tx_rnbase_util_Logger::notice($msg, 'mklib', $data); return true; }
/** * Kürzt die Elemente auf die gewünschte Größe. * * Es wird eine Warnung in die Devlog geschrieben, * wenn mehr als die angegebene Anzahl Element enthalten ist. * * Wenn keine Warnung erzeugt werden soll, * muss bei dem $this->search() Aufruf ein Limit mitgegebenwerden * um die Elemente zu beschränken! Oder auch $this->searchSingle aufrufen. * * @param array $items * @param unknown_type $limit * @param array $options * @return array */ protected function limitResults(array $items, $limit, array $options = array()) { // Leer, wir haben nichts zu tun. if (empty($items)) { return $items; } $count = count($items); // Nur bearbeiten, wenn mehr Elemente vorhanden sind, als notwendig. if ($count > $limit) { // Wir kürzen die Elemente. $items = array_slice($items, 0, $limit); // Wir Schreiben einen Log-Eintrag um den Fehler zu melden. tx_rnbase::load('tx_rnbase_util_Logger'); tx_rnbase_util_Logger::warn('There are more elements(' . $count . ') for limitResults supplied than expected(' . $limit . ').', 'mkhoga'); } return $items; }
/** * @param int $level * @return boolean */ private static function isLogLevel($level) { if (self::$minLog === FALSE) { if (tx_rnbase_util_Extensions::isLoaded('devlog')) { $minLog = tx_rnbase_configurations::getExtensionCfgValue('devlog', 'minLogLevel'); self::$minLog = $minLog !== FALSE ? $minLog : -1; } } $isEnabled = $level >= self::$minLog; return $isEnabled; }
/** * @param Exception $exception * @param array $args * @return void */ protected function logException(Exception $exception, array $args = array()) { $soapClient = $this->getSoapClient(); if ($soapClient instanceof SoapClient) { tx_rnbase_util_Logger::fatal('Access to Soap Interface failed: ' . $exception->getMessage(), 'mklib', array('Fehler', 'functions' => $soapClient->__getFunctions(), 'response' => $soapClient->__getLastResponse(), 'request' => $soapClient->__getLastRequest(), 'args' => $args)); } else { tx_rnbase_util_Logger::fatal('Soap Client was not instanciated!', 'mklib'); } }