/** * Gets a previous slug from the entry log * @param \ride\library\orm\OrmManager $orm * @param \ride\library\reflection\ReflectionHelper $reflectionHelper * @param \ride\web\cms\orm\ContentProperties $contentProperties * @param string $locale Code of the locale * @param string $id Requested slug * @return string|null Current slug of the entry, null if no change found */ protected function getIdFromLog(OrmManager $orm, ReflectionHelper $reflectionHelper, ContentProperties $contentProperties, $locale, $id) { $entryLogChangeModel = $orm->getEntryLogChangeModel(); $meta = $this->model->getMeta(); $isLocalized = $meta->isLocalized(); if ($isLocalized) { $model = $orm->getModel($meta->getLocalizedModelName()); } else { $model = $this->model; } $idField = $contentProperties->getIdField(); // look in the log for the requested id $query = $entryLogChangeModel->createQuery($locale); $query->addCondition('{entryLog.model} = %1%', $model->getName()); $query->addCondition('{fieldName} = %1%', $idField); $query->addCondition('{oldValue} = %1%', $id); $query->addOrderBy('{id} DESC'); $entryLogChange = $query->queryFirst(); if (!$entryLogChange) { // no history of the provided id return null; } $entryLog = $entryLogChange->getEntryLog(); $entryId = $entryLog->getEntry(); // get the original entry $entry = $model->getById($entryId, $this->locale); if (!$entry) { return null; } // retrieve and return the id value from the entry return $reflectionHelper->getProperty($entry, $idField); }