コード例 #1
0
 public function log($level, &$message)
 {
     if ($message instanceof Exception) {
         $exception = $message;
         $backtrace = $exception->getTrace();
         // Add the line throwing the exception to the backtrace.
         array_unshift($backtrace, array('message' => ExceptionHelper::getExceptionMessage($exception), 'file' => $exception->getFile(), 'line' => $exception->getLine()));
         // resolving an issue that exception printing could consume NN MB of log space
         foreach ($backtrace as &$trace) {
             if (!isset($trace['args'])) {
                 continue;
             }
             $updatedArgs = NULL;
             foreach ($trace['args'] as $key => $value) {
                 $isObject = is_object($value);
                 if (is_array($value) || $isObject) {
                     if ($isObject) {
                         $value = (array) $value;
                     }
                     $count = count($value);
                     $max = min(self::$ARGUMENT_ARRAY_INDEXED__VISIBLE_ELEMENT_MAXIMUM, $count);
                     $convertedValue = '';
                     $index = 0;
                     foreach ($value as $k => $v) {
                         if ($index >= $max) {
                             break;
                         }
                         if (strlen($convertedValue) > 0) {
                             $convertedValue .= ', ';
                         }
                         if (is_int($k) && $k == $index) {
                             $convertedValue .= $this->logElementValue($v);
                         } else {
                             $convertedValue .= $k . ': ' . $this->logElementValue($v);
                         }
                         $index++;
                     }
                     // checking if we skip some of the elements
                     if ($count > $max) {
                         $convertedValue .= ', ... ' . ($count - $max) . ' more ' . ($isObject ? 'property(-ies)' : 'element(s)');
                     }
                     $value = ($isObject ? '{' : '[') . $convertedValue . ($isObject ? '}' : ']');
                 }
                 $updatedArgs[$key] = $value;
             }
             $trace['args'] = $updatedArgs;
         }
         unset($trace);
         $message = $backtrace;
     }
 }
    public function doBeforeRecordSubmitted(RecordMetaData $recordMetaData, $recordNumber, array &$record) {
        $result = parent::doBeforeRecordSubmitted($recordMetaData, $recordNumber, $record);

        if ($result) {
            $datatypeFactory = DataTypeFactory::getInstance();

            foreach ($recordMetaData->getColumns() as $column) {
                if (!isset($record[$column->columnIndex])) {
                    continue;
                }

                // FIXME convert data to data type of corresponding lookup dataset column
                if ($column->type->getReferencedDatasetName() != NULL) {
                    continue;
                }

                $handler = $datatypeFactory->getHandler($column->type->applicationType);
                try {
                    $record[$column->columnIndex] = $handler->castValue($record[$column->columnIndex]);
                }
                catch (Exception $e) {
                    $this->exceptionPool[$recordNumber][$column->publicName] = array(
                        'file' => $e->getFile(),
                        'line' => $e->getLine(),
                        'message' => ExceptionHelper::getExceptionMessage($e));
                    $this->exceptionCount++;

                    if ($this->exceptionCount >= $this->exceptionPoolSize) {
                        $this->publishExceptions(TRUE);
                    }
                }
            }

            $result = !isset($this->exceptionPool);
        }

        return $result;
    }
コード例 #3
0
ファイル: Events.php プロジェクト: clevis/orm
 /** @param int */
 private function handleLazy($key)
 {
     $object = call_user_func($this->lazy[$key][0]);
     if (!$object instanceof IListener) {
         $cb = Callback::create($this->lazy[$key][0]);
         throw new BadReturnException(array(NULL, __CLASS__ . " lazy factory {$cb}()", 'Orm\\IListener', $object));
     }
     $types = $this->lazy[$key][1];
     foreach (self::$instructions as $e => $m) {
         if (isset($types[$e])) {
             if ($object instanceof $m[0]) {
                 $this->listeners[$e][$types[$e]] = array(true, array($object, $m[1]));
             } else {
                 throw new InvalidArgumentException(ExceptionHelper::format(array($this, Callback::create($this->lazy[$key][0]), $m[0], $object), "%c1 lazy factory %s2() must return %s3; '%v4' given."));
             }
         } else {
             if ($object instanceof $m[0]) {
                 throw new InvalidArgumentException(ExceptionHelper::format(array($this, Callback::create($this->lazy[$key][0]), $m[0], $object), "%c1 lazy factory %s2() returns not expected %s3; '%v4'."));
             }
         }
     }
     unset($this->lazy[$key]);
 }
コード例 #4
0
 /**
  * Метод сохраняет ошибку выполнения в файл
  * 
  * @param Exception $exception
  */
 public static function dumpError(Exception $exception, $additionalInfo = '')
 {
     if (ConfigIni::exceptionsMaxDumpCount() <= 0) {
         return;
         //---
     }
     $additionalInfo = trim("{$additionalInfo}");
     //Поставим защиту от двойного дампинга ошибки
     $SafePropName = 'ps_ex_dumped';
     if (property_exists($exception, $SafePropName)) {
         return;
         //---
     }
     $exception->{$SafePropName} = true;
     try {
         $INFO[] = 'SERVER: ' . (isset($_SERVER) ? print_r($_SERVER, true) : '');
         $INFO[] = 'REQUEST: ' . (isset($_REQUEST) ? print_r($_REQUEST, true) : '');
         $INFO[] = 'SESSION: ' . (isset($_SESSION) ? print_r($_SESSION, true) : '');
         $INFO[] = 'FILES: ' . (isset($_FILES) ? print_r($_FILES, true) : '');
         if ($additionalInfo) {
             $INFO[] = "ADDITIONAL:\n{$additionalInfo}\n";
         }
         $INFO[] = 'STACK:';
         $INFO[] = ExceptionHelper::formatStackFile($exception);
         $original = ExceptionHelper::extractOriginal($exception);
         $fname = get_file_name($original->getFile());
         $fline = $original->getLine();
         $DM = DirManager::autogen('exceptions');
         if ($DM->getDirContentCnt() >= ConfigIni::exceptionsMaxDumpCount()) {
             $DM->clearDir();
         }
         $DM->getDirItem(null, PsUtil::fileUniqueTime() . " [{$fname} {$fline}]", 'err')->putToFile(implode("\n", $INFO));
     } catch (Exception $ex) {
         //Если в методе дампа эксепшена ошибка - прекращаем выполнение.
         die("Exception [{$exception->getMessage()}] dump error: [{$ex->getMessage()}]");
     }
 }
コード例 #5
0
ファイル: Illust.php プロジェクト: kittolau/gcm
 public function categorize($cat)
 {
     if ($this->isNewRecord) {
         if ($cat == Illust::ILLUST) {
             $this->Illust_cat_title = Illust::ILLUST_CAT_TITLE;
             $this->illust_category_enum = Illust::ILLUST;
             return;
         }
         if ($cat == Illust::MANGA) {
             $this->Illust_cat_title = Illust::MANGA_CAT_TITLE;
             $this->illust_category_enum = Illust::MANGA;
             return;
         }
         ExceptionHelper::throw404(get_class($this), "categorize", "cannot categorize for " . $cat);
     }
 }
コード例 #6
0
ファイル: GroupProduct.php プロジェクト: kittolau/gcm
 public function categorize($cat)
 {
     if ($this->isNewRecord) {
         if ($cat == GroupProduct::BOOK) {
             $this->GroupProduct_cat_title = GroupProduct::BOOK_CAT_TITLE;
             $this->product_catagory_enum = GroupProduct::BOOK;
             return;
         }
         if ($cat == GroupProduct::GIFT) {
             $this->GroupProduct_cat_title = GroupProduct::GIFT_CAT_TITLE;
             $this->product_catagory_enum = GroupProduct::GIFT;
             return;
         }
         if ($cat == GroupProduct::ELECT) {
             $this->GroupProduct_cat_title = GroupProduct::ELECT_CAT_TITLE;
             $this->product_catagory_enum = GroupProduct::ELECT;
             return;
         }
         ExceptionHelper::throw404(get_class($this), "categorize", "cannot categorize for " . $cat);
     }
 }
    public function log($level, &$message) {
        if ($message instanceof Exception) {
            $exception = $message;

            $backtrace = $exception->getTrace();
            // Add the line throwing the exception to the backtrace.
            array_unshift(
                $backtrace,
                array(
                    'message' => ExceptionHelper::getExceptionMessage($exception),
                    'file' => $exception->getFile(),
                    'line' => $exception->getLine()));

            // resolving an issue that exception printing could consume NN MB of log space
            foreach ($backtrace as &$trace) {
                if (!isset($trace['args'])) {
                    continue;
                }

                $updatedArgs = NULL;
                foreach ($trace['args'] as $argKey => $argValue) {
                    $isObject = is_object($argValue);
                    if (is_array($argValue) || $isObject) {
                        $value = $isObject ? get_object_vars($argValue) : $argValue;

                        $count = count($value);
                        $max = min(self::$ARGUMENT_ARRAY_INDEXED__VISIBLE_ELEMENT_MAXIMUM, $count);

                        $convertedValue = '';

                        $index = 0;
                        foreach ($value as $k => $v) {
                            if ($index >= $max) {
                                break;
                            }

                            if ($convertedValue != '') {
                                $convertedValue .= ', ';
                            }
                            if (is_int($k) && ($k == $index)) {
                                $convertedValue .= $this->logElementValue($v);
                            }
                            else {
                                $convertedValue .= $k . self::$FORMATTER_OPTION__COMPOSITE_ELEMENT_KEY_VALUE_DELIMITER . $this->logElementValue($v);
                            }

                            $index++;
                        }
                        // checking if we skip some of the elements
                        if ($count > $max) {
                            $convertedValue .= ', ... ' . ($count - $max) . ' more ' . ($isObject ? 'property(-ies)' : 'element(s)');
                        }

                        if ($isObject) {
                            $s = get_class($argValue) . '{';
                            if ($convertedValue == '') {
                                $s .= '...';
                            }
                            $s .= '}';
                            $argValue = $s;
                        }
                        else {
                            $argValue = '[' . $convertedValue . ']';
                        }
                    }

                    $updatedArgs[$argKey] = $argValue;
                }
                $trace['args'] = $updatedArgs;
            }
            unset($trace);

            $message = $backtrace;
        }
    }
コード例 #8
0
    public function parse(AbstractDataProvider $dataProvider, array $dataSubmitters = NULL) {
        $skippedRecordCount = 0;
        $loadedRecordCount = 0;

        $timeStart = microtime(TRUE);
        if ($dataProvider->openResource()) {
            LogHelper::log_notice(t(
                'Parsing @limitRecordCount records. Skipping first @skipRecordCount records (memory usage: @memoryUsed) ...',
                array(
                    '@skipRecordCount' => $this->skipRecordCount,
                    '@limitRecordCount' => (isset($this->limitRecordCount) ? $this->limitRecordCount : t('all')),
                    '@memoryUsed' => memory_get_usage())));

            try {
                if ($this->initializeProcessing($dataSubmitters)) {
                    // preparing list of columns
                    $this->prepareMetaData($dataProvider, $dataSubmitters);

                    $metadataColumnCount = $this->metadata->getColumnCount(FALSE, TRUE);

                    if ((!isset($this->limitRecordCount) || ($this->limitRecordCount > 0))
                            && $this->executeBeforeProcessingRecords($dataSubmitters, $dataProvider)) {
                        // processing records
                        $fileProcessedCompletely = FALSE;
                        while (!isset($this->limitRecordCount) || ($loadedRecordCount < $this->limitRecordCount)) {
                            $dataProvider->startReading();
                            $record = $this->parseNextRecord($dataProvider, $dataSubmitters);

                            // number of loaded columns should match number of columns in meta data
                            if (isset($record)) {
                                $attempt = 1;
                                while (TRUE) {
                                    $recordColumnCount = count($record);
                                    if ($recordColumnCount == $metadataColumnCount) {
                                        break;
                                    }
                                    else {
                                        if ($attempt > self::$MAX_ATTEMPTS_TO_RESOLVE_PARSING_ISSUES) {
                                            $dataProvider->endReading();
                                            LogHelper::log_debug($this->metadata);
                                            LogHelper::log_debug($record);
                                            throw new DataParserException(t(
                                                'Expected to load values for %metadataColumnCount columns. Loaded %loadedColumnCount [line: %lineNumber]',
                                                array('%metadataColumnCount' => $metadataColumnCount, '%loadedColumnCount' => $recordColumnCount, '%lineNumber' => $dataProvider->getCurrentLineNumber())));
                                        }

                                        $dataProvider->rollbackReading();
                                        $dataProvider->startReading();
                                        $record = $this->parseNextRecord($dataProvider, $dataSubmitters, $attempt);

                                        $attempt++;
                                    }
                                }
                            }
                            $dataProvider->endReading();

                            // checking if we reached the end
                            if (!isset($record)) {
                                $fileProcessedCompletely  = TRUE;
                                break;
                            }

                            // skipping required number of records
                            if ($skippedRecordCount < $this->skipRecordCount) {
                                $skippedRecordCount++;
                                continue;
                            }

                            $this->postProcessColumnValues($record);

                            // checking if we need to skip processing the record
                            $recordNumber = $dataProvider->getCurrentLineNumber();
                            if ($this->executeBeforeRecordSubmitted($dataSubmitters, $recordNumber, $record)) {
                                $this->submitRecord($dataSubmitters, $recordNumber, $record);
                                $this->executeAfterRecordSubmitted($dataSubmitters, $recordNumber, $record);

                                $loadedRecordCount++;
                                if (($loadedRecordCount % 1000) == 0) {
                                    LogHelper::log_info(t(
                                        'Processed @recordCount records so far (memory usage: @memoryUsed)',
                                        array('@recordCount' => $loadedRecordCount, '@memoryUsed' => memory_get_usage())));
                                }
                            }
                        }

                        $this->executeAfterProcessingRecords($dataSubmitters, $fileProcessedCompletely);
                    }

                    $this->finishProcessing($dataSubmitters);
                }
            }
            catch (DataParserException $e) {
                LogHelper::log_warn(t('Place of original exception @file:@line', array('@file' => $e->getFile(), '@line' => $e->getLine())));

                try {
                    $this->abortProcessing($dataSubmitters);
                }
                catch (Exception $ne) {
                    // we do not need to rethrow this exception. We need to preserve and rethrow original exception
                    LogHelper::log_error($ne);
                }

                try {
                    $dataProvider->closeResource();
                }
                catch (Exception $ne) {
                    // we do not need to rethrow this exception. We need to preserve and rethrow original exception
                    LogHelper::log_error($ne);
                }

                throw new IllegalStateException($e->getMessage());
            }
            catch (Exception $e) {
                LogHelper::log_warn(t('Place of original exception @file:@line', array('@file' => $e->getFile(), '@line' => $e->getLine())));

                try {
                    $this->abortProcessing($dataSubmitters);
                }
                catch (Exception $ne) {
                    // we do not need to rethrow this exception. We need to preserve and rethrow original exception
                    LogHelper::log_error($ne);
                }

                $ise = new IllegalStateException(
                    ExceptionHelper::getExceptionMessage($e) . t(' [%lineNumber line(s) parsed so far]', array('%lineNumber' => $dataProvider->getCurrentLineNumber())),
                    0, $e);
                try {
                    $dataProvider->closeResource();
                }
                catch (Exception $ne) {
                    // we do not need to rethrow this exception. We need to preserve and rethrow original exception
                    LogHelper::log_error($ne);
                }

                throw $ise;
            }

            $dataProvider->closeResource();
        }

        LogHelper::log_notice(t(
            'Processing @recordCount record(s) took !executionTime',
            array('@recordCount' => $loadedRecordCount, '!executionTime' => LogHelper::formatExecutionTime($timeStart))));

        return $loadedRecordCount;
    }