Adds order value if not already set in query.

@param \Cake\Event\Event $event The beforeFind event that was fired.
@param \Cake\ORM\Query $query The query object.
@param \ArrayObject $options The options passed to the find method.

@return void
974010
public function beforeFind(Event $event, Query $query, ArrayObject $options)
    {
        if (!$query->clause('order')) {
            $query->order([$this->_table->aliasField($this->_config['order']) => 'ASC']);
        }
    }
729622
public function query( $query, $options = 0 ) {

		$result                   = $this->wpdb->get_results( (string) $query );
		$this->last_affected_rows = (int) $this->wpdb->rows_affected;
		$this->last_insert_id     = (int) $this->wpdb->insert_id;
		$this->last_statement     = NULL;
		if ( ! is_array( $result ) )
			$result = [];

		return new GenericResult( $result );
	}
1345329
private function _runQuery($query, $options)
    {
        $this->_testQueryStarts($query, '[select|show]');
        $statement = $this->_executeQuery($query, $options);
        if (is_object($statement) && $statement instanceof \PDOStatement) {
            return $statement;
        }
        else {
            $this->_error(FQDBException::INTERNAL_ASSERTION_FAIL, FQDBException::FQDB_CODE);
        }
    }
797694
private function executeQuery($document, array $query, array $options)
    {
        $className  = get_class($document);
        $class      = $this->dm->getClassMetadata($className);
        $findQuery  = $this->getQueryForDocument($class, $document);
        $collection = $this->dm->getDocumentCollection($className);
        $collection->update($findQuery, $query, $options);
    }
1009666
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options): void
    {
        if (empty($entity->get('source'))) {
            $entity->set('source', 'Plugin__');
        }

        // Default calendar color in case none is given.
        if (empty($entity->get('color'))) {
            $entity->set('color', $this->getColor($entity));
        }

        /** @var \Qobo\Calendar\Model\Table\CalendarEventsTable $calendarEventsTable */
        $calendarEventsTable = TableRegistry::get('Qobo/Calendar.CalendarEvents');
        $default = $calendarEventsTable->getEventTypeBy('default');
        $defaultKey = key($default);
        if (!empty($entity->get('event_types'))) {
            $types = json_decode($entity->get('event_types'), true);

            if (!in_array($defaultKey, $types)) {
                array_push($types, $defaultKey);
                asort($types);
                $entity->set('event_types', json_encode($types));
            }
        } else {
            $entity->set('event_types', json_encode([$defaultKey]));
        }
    }
865322
public function beforeSave($event, $entity, $options)
    {
        if (!empty($entity->new_password)) {
            $entity->password = $entity->new_password; // set for password-changes
        }
    }
893263
public function prepare($query, array $options = array())
    {
        // Replace prefix placeholder with prefix
        $query = str_replace("{prefix}", $this->prefix, $query);

        // Log last query and query count
        $this->lastQuery = $query;
        $this->queryCount++;

        // Statement time
        return new Statement($this->connection->prepare($query, $options), $this->connectionName);
    }
29984
public function update($query, $data, $option = array())
    {
        return $this->collection->update($query, $data, $option);
    }
962899
public function query($query, $options = [])
    {
        $url = $this->instanceURLRepo->get();
        $url .= $this->resourceRepo->get('query');
        $url .= '?q=';
        $url .= urlencode($query);

        $queryResults = $this->request($url, $options);

        return $queryResults;
    }
151560
public function findSlugged(Query $query, array $options) {
		if (empty($options['slug'])) {
			throw new InvalidArgumentException("The 'slug' key is required for find('slugged')");
		}

		return $query->where([$this->_config['field'] => $options['slug']]);
	}
675346
public function queryAssoc($query, $options = array())
    {
        $statement = $this->_runQuery($query, $options);
        return $statement->fetch(\PDO::FETCH_ASSOC);
    }
480293
protected function setOrder(Select $query, array $order)
    {
        // Normalize to [['column', 'direction']] format if only one column
        if (! is_array(Arr::get($order, 0))) {
            $order = [$order];
        }

        foreach ($order as $key => $orderValue) {
            if (is_array($orderValue)) {
                // Column and direction
                $query->order(
                    Arr::get($orderValue, 0).' '.Arr::get($orderValue, 1)
                );
            }
        }

        return $query;
    }
300549
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary) {
		$this->encodeBitmaskConditions($query);

		$field = $this->_config['field'];
		if (!($mappedField = $this->_config['mappedField'])) {
			$mappedField = $field;
		}

		$mapper = function ($row, $key, $mr) use ($field, $mappedField) {
			/**
			 * @var \Cake\Collection\Iterator\MapReduce $mr
			 * @var \Cake\Datasource\EntityInterface|array $row
			 */
			if (!is_object($row)) {
				if (isset($row[$field])) {
					$row[$mappedField] = $this->decodeBitmask($row[$field]);
				}
				$mr->emit($row);
				return;
			}

			/** @var \Cake\Datasource\EntityInterface $entity */
			$entity = $row;
			$entity->set($mappedField, $this->decodeBitmask($entity->get($field)));
			$entity->setDirty($mappedField, false);
			$mr->emit($entity);
		};
		$query->mapReduce($mapper);
	}
894660
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) : void
    {
        // @todo this will be removed once saved searches table schema is adjusted
        $saved = Hash::get($data, 'content.saved', []);
        if (! empty($saved)) {
            $data['content']['latest'] = $saved;
        }
    }
516880
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
    {
        $field = $this->getTrashField();
        $addCondition = true;

        $query->traverseExpressions(function ($expression) use (&$addCondition, $field) {
            if (!$addCondition) {
                return;
            }

            if ($expression instanceof IdentifierExpression
                && $expression->getIdentifier() === $field
            ) {
                $addCondition = false;

                return;
            }

            if (($expression instanceof Comparison || $expression instanceof BetweenExpression)
                && $expression->getField() === $field
            ) {
                $addCondition = false;
            }
        });

        if ($addCondition) {
            $query->andWhere($query->newExpr()->isNull($field));
        }
    }
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);
	}
47195
public function afterSave($event, $entity, $options)
    {
        $fields = $this->getFieldList();
        $storedToSave = [];
        foreach ($fields as $field => $data) {
            if ($this->_ifUploaded($entity, $field)) {
                if ($this->_uploadFile($entity, $field)) {
                    if (!key_exists($field, $this->_savedFields)) {
                        $this->_savedFields[$field] = true;
                        $storedToSave[] = $this->_setUploadColumns($entity, $field);
                    }
                }
            }
        }
        foreach ($storedToSave as $toSave) {
            $event->subject()->save($toSave);
        }
        $this->_savedFields = [];
    }