Handle Processing

@param ImageRecord        $record
@param ImageConfiguration $config
@return StandardServiceResponse
496558
public function handle(ImageRecord $record, ImageConfiguration $config)
    {
        /* build path */
        $path_to_record = "$record->path/$record->uuid/$record->filename";

        /* get file from storage */
        $image = $this->storage->get($record->disk, $path_to_record);

        /* move file to primary storage if not already there */
        if ($record->disk !== $config->primary_disk) {
            $this->storage->move($path_to_record, $path_to_record, $record->disk, $config->primary_disk);
            $this->image_repo->update($record, ['disk' => $config->primary_disk]);
        }

        /* create transformation for each size */
        $transformation_records = $this->_createTransformations($image, $config, $record);

        $this->image_repo->update($record, ['status' => 'complete']);

        return new StandardServiceResponse(
            true,
            ['image' => $record, 'image_transformations' => $transformation_records],
            'Image processing completed successfully'
        );
    }
541949
protected function processFormat(array $record, string $tag): string
    {
        if (preg_match_all('/\{\{(.*?)\}\}/', $tag, $matches)) {
            foreach ($matches[1] as $match) {
                if (!isset($record[$match])) {
                    throw new \LogicException('No such field in the record');
                }
                $tag = str_replace(sprintf('{{%s}}', $match), $record[$match], $tag);
            }
        }

        return $tag;
    }
641876
protected function prepare(Collection $record)
    {
        $placeholders = $record->toArray();
        
        $message = $placeholders['message'];
        unset($placeholders['message']);
        
        $content = $message['content'];
        $context = $placeholders + $message['context'];
        
        $flattened = [];
        $this->flatten($context, [], $flattened);
        
        $message = $this->replace($content, $flattened);
        
        $placeholders['message'] = $message;
        
        return $placeholders;
    }
1296601
protected function build_tool_consumer_object($record, ToolConsumer $consumer) {
        $consumer->setRecordId($record->id);
        $consumer->name = $record->name;
        $key = empty($record->consumerkey) ? $record->consumerkey256 : $record->consumerkey;
        $consumer->setKey($key);
        $consumer->secret = $record->secret;
        $consumer->ltiVersion = $record->ltiversion;
        $consumer->consumerName = $record->consumername;
        $consumer->consumerVersion = $record->consumerversion;
        $consumer->consumerGuid = $record->consumerguid;
        $consumer->profile = json_decode($record->profile);
        $consumer->toolProxy = $record->toolproxy;
        $settings = unserialize($record->settings);
        if (!is_array($settings)) {
            $settings = array();
        }
        $consumer->setSettings($settings);
        $consumer->protected = $record->protected == 1;
        $consumer->enabled = $record->enabled == 1;
        $consumer->enableFrom = null;
        if (!is_null($record->enablefrom)) {
            $consumer->enableFrom = $record->enablefrom;
        }
        $consumer->enableUntil = null;
        if (!is_null($record->enableuntil)) {
            $consumer->enableUntil = $record->enableuntil;
        }
        $consumer->lastAccess = null;
        if (!is_null($record->lastaccess)) {
            $consumer->lastAccess = $record->lastaccess;
        }
        $consumer->created = $record->created;
        $consumer->updated = $record->updated;
    }
1043683
protected function parseRecord($record, $fields_info, $filter_info = null, $for_update = false, $old_record = null)
    {
        unset($record['Timestamp']); // not set-able

        return parent::parseRecord($record, $fields_info, $filter_info, $for_update, $old_record);
    }
92158
public static function record(Recorder $recorder)
    {
        return function (callable $handler) use ($recorder) {
            return function ($request, array $options) use ($handler, $recorder) {
                return $handler($request, $options)->then(
                  function ($response) use ($request, $recorder) {
                      $recorder->record($response);

                      return $response;
                  },
                  function ($reason) use ($request, $recorder) {
                      $response = $reason instanceof RequestException
                        ? $reason->getResponse()
                        : null;
                      if ($response) {
                          $recorder->record($response);
                      }

                      return \GuzzleHttp\Promise\rejection_for($reason);
                  }
                );
            };
        };
    }
713025
public function format( IRecord $record )
    {
        if ( !$record instanceof ErrorLogRecord )
        {
            throw new LogException( 'Record must be an instance of ErrorLogRecord' );
        }

        $format = '[%s] [%s] [%s] %s';

        $result = sprintf( $format,
                           $record->getDate()->format( 'D M d G:i:s T' ),
                           Log::getLevelString( $record->getLevel() ),
                           $record->getClientIP(),
                           $record->getText()
        );

        $result .= PHP_EOL;

        return $result;
    }
98032
public function handle( Record $record )
    {
        if (is_null( $this->aggregateRecord )) {
            $this->setAggregateRecord( $record ); // first record

            return null;
        }

        if ($this->aggregateRecord->pushRecord( $record )) {
            return null;
        }

        return $this->setAggregateRecord( $record );
    }
1015742
public function transformRecordToEntities(Record $record)
    {
        if (get_class($record) == $this->record) {
            return $record;
        }

        $newRecord = $this->getRecord();
        $newRecord->setData($record->data());
        $newRecord->setOriginalFromData();

        if ($record->isSaved()) {
            $newRecord->setSaved();
        }

        return $newRecord;
    }
818395
public function pushRecord(Record $record)
    {
        switch (true) {
            case $record->getType()->isStdout():
                $this->stdout .= $record->getContent();
                break;
            case $record->getType()->isStderr():
                $this->stderr .= $record->getContent();
                break;
            case $record->getType()->isEndRequest():
                return new Response($this->requestId, new StringReader($this->stdout), new StringReader($this->stderr));
                break;
            default:
                throw new \RuntimeException(sprintf('Unknown package type \'%d\'', $record->getType()));
                break;
        }
    }
13210
protected function reload_from_record($record, $clean = false) {
        $this->id           = $record->id;
        $this->tourid       = $record->tourid;
        if ($clean) {
            $this->title    = clean_param($record->title, PARAM_TEXT);
            $this->content  = clean_text($record->content);
        } else {
            $this->title    = $record->title;
            $this->content  = $record->content;
        }
        $this->targettype   = $record->targettype;
        $this->targetvalue  = $record->targetvalue;
        $this->sortorder    = $record->sortorder;
        $this->config       = json_decode($record->configdata);
        $this->dirty        = false;

        return $this;
    }
1290972
public function handleError(
        \Plop\RecordInterface $record,
        \Exception $exception
    ) {
        $stderr = $this->getStderr();
        fprintf($stderr, "%s\n", $exception);
        fclose($stderr);
        return $this;
    }
995838
protected static function patchExisting($service, $resource, $record, $key)
    {
        $api = $service . '/' . $resource;
        $value = array_get($record, $key);
        switch ($api) {
            case 'system/event_script':
            case 'system/custom':
            case 'user/custom':
            case $service . '/_schema':
                $result = ServiceManager::handleRequest(
                    $service,
                    Verbs::PATCH,
                    $resource . '/' . $value,
                    [],
                    [],
                    $record,
                    null,
                    true,
                    true
                );
                if ($result->getStatusCode() === 404) {
                    throw new InternalServerErrorException(
                        'Could not find existing resource to PATCH for ' .
                        $service . '/' . $resource . '/' . $value
                    );
                }
                if ($result->getStatusCode() >= 300) {
                    throw ResponseFactory::createExceptionFromResponse($result);
                }

                return true;
            default:
                /** @var ServiceResponseInterface $result */
                $result = ServiceManager::handleRequest(
                    $service,
                    Verbs::GET,
                    $resource,
                    ['filter' => "$key='$value'"],
                    [],
                    null,
                    null,
                    true,
                    true
                );
                if ($result->getStatusCode() === 404) {
                    throw new InternalServerErrorException(
                        'Could not find existing resource for ' .
                        $service . '/' . $resource .
                        ' using ' . $key . ' = ' . $value
                    );
                }
                if ($result->getStatusCode() >= 300) {
                    throw ResponseFactory::createExceptionFromResponse($result);
                }
                $content = ResourcesWrapper::unwrapResources($result->getContent());
                $existing = array_get($content, 0);
                $existingId = array_get($existing, BaseModel::getPrimaryKeyStatic());
                if (!empty($existingId)) {
                    unset($record[BaseModel::getPrimaryKeyStatic()]);
                    $payload = $record;
                    if (in_array($api, ['system/admin', 'system/user'])) {
                        unset($payload['password']);
                    }
                    $result = ServiceManager::handleRequest(
                        $service,
                        Verbs::PATCH,
                        $resource . '/' . $existingId,
                        [],
                        [],
                        $payload,
                        null,
                        true,
                        true
                    );
                    if ($result->getStatusCode() === 404) {
                        throw new InternalServerErrorException(
                            'Could not find existing resource to PATCH for ' .
                            $service . '/' . $resource . '/' . $existingId
                        );
                    }
                    if ($result->getStatusCode() >= 300) {
                        throw ResponseFactory::createExceptionFromResponse($result);
                    }

                    if (in_array($api, ['system/admin', 'system/user'])) {
                        static::updateUserPassword([$record]);
                    }

                    return true;
                } else {
                    throw new InternalServerErrorException(
                        'Could not get ID for ' .
                        $service . '/' . $resource .
                        ' resource using ID field ' . BaseModel::getPrimaryKeyStatic()
                    );
                }
                break;
        }
    }
1004709
public function handle( IRecord $record )
    {
        // check if we should be logging this record
        if ( $record->getLevel() >= $this->_level )
        {
            // check if file exists
            if ( !file_exists( $this->fileName ) )
            {
                if ( !touch( $this->fileName ) )
                {
                    throw new LogException( 'Failed to create log file: ' . $this->fileName );
                }
            }

            file_put_contents(
                $this->fileName,
                $this->getFormatter()->format( $record ),
                FILE_APPEND
            );
        }
    }
951129
public function processConfiguration($config)
    {
        $factory = new ConfigurationProcessorFactory();
        $processor = $factory->create(gettype($config));
        $config = $processor->convertToObjectConfiguration($config);
        $processor->validate($config);
        $this->config = $config;
    }
285401
protected function prepareContentData($record)
    {
        $dataArray = array(
            'token'       => $this->token,
            'channel'     => $this->channel,
            'username'    => $this->username,
            'text'        => '',
            'attachments' => array(),
        );

        if ($this->formatter) {
            $message = $this->formatter->format($record);
        } else {
            $message = $record['message'];
        }

        if ($this->useAttachment) {
            $attachment = array(
                'fallback' => $message,
                'color'    => $this->getAttachmentColor($record['level']),
                'fields'   => array(),
            );

            if ($this->useShortAttachment) {
                $attachment['title'] = $record['level_name'];
                $attachment['text'] = $message;
            } else {
                $attachment['title'] = 'Message';
                $attachment['text'] = $message;
                $attachment['fields'][] = array(
                    'title' => 'Level',
                    'value' => $record['level_name'],
                    'short' => true,
                );
            }

            if ($this->includeContextAndExtra) {
                if (!empty($record['extra'])) {
                    if ($this->useShortAttachment) {
                        $attachment['fields'][] = array(
                            'title' => "Extra",
                            'value' => $this->stringify($record['extra']),
                            'short' => $this->useShortAttachment,
                        );
                    } else {
                        // Add all extra fields as individual fields in attachment
                        foreach ($record['extra'] as $var => $val) {
                            $attachment['fields'][] = array(
                                'title' => $var,
                                'value' => $val,
                                'short' => $this->useShortAttachment,
                            );
                        }
                    }
                }

                if (!empty($record['context'])) {
                    if ($this->useShortAttachment) {
                        $attachment['fields'][] = array(
                            'title' => "Context",
                            'value' => $this->stringify($record['context']),
                            'short' => $this->useShortAttachment,
                        );
                    } else {
                        // Add all context fields as individual fields in attachment
                        foreach ($record['context'] as $var => $val) {
                            $attachment['fields'][] = array(
                                'title' => $var,
                                'value' => $val,
                                'short' => $this->useShortAttachment,
                            );
                        }
                    }
                }
            }

            $dataArray['attachments'] = json_encode(array($attachment));
        } else {
            $dataArray['text'] = $message;
        }

        if ($this->iconEmoji) {
            $dataArray['icon_emoji'] = ":{$this->iconEmoji}:";
        }

        return $dataArray;
    }
133504
public function fillRecord(Record $record)
    {
        /**
         * Get record from right entity.
         */
        $rightRecord = $this->getRightRecord(
            $this->getRightEntity(),
            $this->primaryKey,
            $record->{$this->foreignKey}
        );

        /**
         * Set relation.
         */
        $record->setRelation($this->fill, $rightRecord);

        /**
         * Fill relations.
         */
        $this->fillRecordWithRelations($record);
    }