@param \Cake\Event\Event $event
@param \Cake\Datasource\EntityInterface $entity
@param \ArrayObject $options
@param string $operation

@return void
167408
public function beforeRules(Event $event, EntityInterface $entity, ArrayObject $options, $operation) {
		if ($this->_config['on'] !== 'beforeRules' || !$options['checkRules']) {
			return;
		}
		$this->encodeBitmaskData($entity);
	}
590157
public function beforeSave($event, $entity, $options)
    {
        $uploads = [];
        $fields = $this->getFieldList();
        foreach ($fields as $field => $data) {
            if (!is_string($entity->get($field))) {
                $uploads[$field] = $entity->get($field);
                $entity->set($field, null);
            }

            if (!$entity->isNew()) {
                $dirtyField = $entity->dirty($field);
                $originalField = $entity->getOriginal($field);
                if ($dirtyField && !is_null($originalField) && !is_array($originalField)) {
                    $fieldConfig = $this->config($field);

                    if ($fieldConfig['removeFileOnUpdate']) {
                        $this->_removeFile($entity->getOriginal($field));
                    }
                }
            }
        }
        $this->_uploads = $uploads;
    }
777495
public function path(EntityInterface $entity, array $options = []) {
		$config = array_merge($this->getConfig(), $options);
		$path = '';
		$path = $this->_pathPrefix($entity, $path, $config);
		$path = $this->_path($entity, $path, $config);
		$path = $this->_pathSuffix($entity, $path, $config);

		return $this->ensureSlash($path, 'after');
	}
974010
public function beforeFind(Event $event, Query $query, ArrayObject $options)
    {
        if (!$query->clause('order')) {
            $query->order([$this->_table->aliasField($this->_config['order']) => 'ASC']);
        }
    }
580044
public function saveArray(array $entity, array $options = []) {
		$entity = $this->newEntity($entity, $options);
		return $this->save($entity, $options);
	}
1282778
public function save($entity, $options = [])
    {
        if ($this->link() !== static::LINK_KEY) {
            return true;
        }

        $name = $this->name();
        if (!isset($entity->{$name})) {
            return true;
        }

        $conditions = $this->match($entity);
        $related = $entity->{$name};
        $result = !!$related->set($conditions)->save($options);
        return $result;
    }
481869
public function handleEvent(Event $event, $ormObject, $options)
    {
        $key = $this->getConfig('optionKey');
        if (empty($options[$key]) && !empty($this->_currentUser)) {
            $options[$key] = $this->_currentUser;
        }
    }
683516
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options) : void
    {
        EventManager::instance()->dispatch(new Event(
            (string)EventName::MODEL_AFTER_SAVE(),
            $this,
            ['entity' => $entity, 'options' => ['current_user' => User::getCurrentUser()]]
        ));
    }
594296
public function afterSave(Event $event, EntityInterface $entity) {
		if ($this->_checkEvent($event) && $entity->isNew()) {
			$fileField = $this->getConfig('fileField');

			$hash = StorageUtils::getFileHash($entity->get($fileField)['tmp_name']);
			$path = $this->pathBuilder()->fullPath($entity);

			$entity->set('hash', $hash);
			$entity->set('path', $path);

			if (!$this->_storeFile($event)) {
				return;
			}

			$event->result = true;
			$event->stopPropagation();
		}
	}
721411
public function getPluginCalendars(Event $event, array $options = []): void
    {
        $content = $result = [];

        /** @var \Qobo\Calendar\Model\Table\CalendarsTable $table */
        $table = TableRegistry::get('Qobo/Calendar.Calendars');

        if (!empty($event->result)) {
            $result = $event->result;
        }

        // locally created calendars don't have source_id (external link).
        $options = array_merge($options, [
            'conditions' => [
                'source LIKE' => 'Plugin__%',
            ]
        ]);

        $calendars = $table->getCalendars($options);

        if (empty($calendars)) {
            return;
        }

        foreach ($calendars as $k => $calendar) {
            unset($calendar->calendar_events);

            $encoded = (string)json_encode($calendar);
            if (json_last_error() !== JSON_ERROR_NONE) {
                throw new \RuntimeException(json_last_error_msg());
            }

            $content[$k]['calendar'] = json_decode($encoded, true);
        }

        if (!empty($content)) {
            $result = array_merge($result, $content);
        }

        $event->result = $result;
    }
125544
public function validates($entity, $options = [])
    {
        $fieldname = $this->name();

        if (!isset($entity->{$fieldname})) {
            return true;
        }
        return $entity->{$fieldname}->validates($options);
    }
938917
public static function init(PDO $pdo, $options = [])
    {
        DB::init($pdo);
        self::$initOptions = $options;
    }
149121
public function execute(StorageInterface $storage, Operations $operations)
    {
        foreach ($operations->getOperations() as $operation) {
            if ($operation instanceof AddDocumentOperation) {
                $document = $operation->getDocument();
                $event = new DocumentEvent($document);
                if ($this->eventDispatcher->dispatch(IndexerEvents::BEFORE_STORAGE_ADD_DOCUMENT, $event)
                    ->isPropagationStopped()
                ) {
                    continue;
                }

                $storage->addDocument($document);

                $event = new DocumentEvent($document);
                $this->eventDispatcher->dispatch(IndexerEvents::STORAGE_ADD_DOCUMENT, $event);
            } elseif ($operation instanceof AddIdentityOperation) {
                throw new InvalidArgumentException('Add identity command not supported by run().');
            } elseif ($operation instanceof UpdateDocumentOperation) {
                $document = $operation->getDocument();
                $event = new DocumentEvent($document);
                if ($this->eventDispatcher->dispatch(IndexerEvents::BEFORE_STORAGE_UPDATE_DOCUMENT, $event)->isPropagationStopped()) {
                    continue;
                }

                $storage->updateDocument($document);

                $event = new DocumentEvent($document);
                $this->eventDispatcher->dispatch(IndexerEvents::STORAGE_UPDATE_DOCUMENT, $event);
            } elseif ($operation instanceof UpdateIdentityOperation) {
                throw new InvalidArgumentException('Update identity command not supported by run().');
            } elseif ($operation instanceof DeleteDocumentOperation) {
                $storage->deleteDocument($operation->getDocument());
            } elseif ($operation instanceof DeleteIdentityOperation) {
                $storage->delete($operation->getIdentity());
            } elseif ($operation instanceof DeleteTypeOperation) {
                $storage->deleteType($operation->getType());
            } elseif ($operation instanceof DeleteAllOperation) {
                $storage->deleteAll();
            } elseif ($operation instanceof FlushOperation) {
                if ($storage instanceof Flushable) {
                    $storage->flush();
                }
            } elseif ($operation instanceof OptimizeOperation) {
                if ($storage instanceof Optimizable) {
                    $storage->optimize();
                }
            } elseif ($operation instanceof CommitOperation) {
                if ($storage instanceof Commitable) {
                    $storage->commit();
                }
            } elseif ($operation instanceof RollbackOperation) {
                if ($storage instanceof Rollbackable) {
                    $storage->rollback();
                }
            }
        }

        return true;
    }
690432
public function afterDelete(Event $event, EntityInterface $entity, ArrayObject $options) {
		$field = $this->getConfig('field');

		$value = $entity->get($field);
		if (!$value) {
			return;
		}

		$conditions = $this->buildConditions($entity);

		$order = $this->getConfig('findOrder');
		if ($order === null) {
			$order = [];
			if ($this->_table->getSchema()->getColumn('modified')) {
				$order['modified'] = 'DESC';
			}
		}
		$entity = $this->_table->find()->where($conditions)->order($order)->first();
		if (!$entity) {
			// This should be caught with a validation rule if at least one "primary" must exist
			return;
		}

		$entity->set($field, true);
		$this->_table->saveOrFail($entity);
	}
900121
public function createAllImageVersions(EntityInterface $entity, array $options = []) {
		return $this->createImageVersions(
			$entity,
			$this->getAllVersionsKeysForModel($entity->model),
			$options
		);
	}
629343
public function delete(EntityInterface $resource, $options = [])
    {
        return (bool)$this->query()->delete()->where([
            $this->getPrimaryKey() => $resource->get($this->getPrimaryKey())
        ])->execute();
    }
277844
private function configureGet(Get $operation, array $options)
    {
        if (!$operation->summary) {
            if ($options['returns'] == Route::RETURNS_ENTITY) {
                $operation->summary = 'Fetch a '.$options['entity_name'].' entity';
            } else {
                $operation->summary = 'Fetch a collection of '.$options['entity_name'].' entities';
            }
        }

        // verify that the x-collection property is set
        if ($options['returns'] == Route::RETURNS_COLLECTION) {
            $schema = [
                'type' => 'array',
                'items' => [
                    '$ref' => '#/definitions/'.$options['entity_name'],
                ],
            ];
        } else {
            $schema = [
                '$ref' => '#/definitions/'.$options['entity_name'],
            ];
        }

        if ($options['returns'] == Route::RETURNS_ENTITY) {
            $successText = 'Entity Found and Returned';
        } else {
            $successText = 'Entity Collection Found and Returned';
        }

        $this->appendResponses(
            $operation,
            [
                new Response(
                    [
                        'response' => 200,
                        'description' => $successText,
                        'schema' => $schema,
                    ]
                ),
                new Response(
                    [
                        'response' => 404,
                        'description' => 'Entity Not Found',
                    ]
                ),
            ]
        );
    }