/**
  * 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);
 }
 /**
  * Parses the provided variable
  * @param string $variable Full variable
  * @return mixed Value of the variable if resolved, null otherwise
  */
 public function parseVariable($variable)
 {
     $tokens = explode('.', $variable);
     $numTokens = count($tokens);
     if ($numTokens < 2) {
         return null;
     }
     $node = $this->textParser->getNode();
     if ($numTokens === 2 || $tokens[0] === 'node' && $tokens[1] === 'var') {
         while ($node && !$node instanceof EntryNode) {
             $node = $node->getParentNode();
         }
         if (!$node) {
             return null;
         }
     }
     $value = null;
     if ($tokens[0] === 'entry' && $numTokens === 2) {
         switch ($tokens[1]) {
             case NodeVariableParser::VARIABLE_URL:
                 $value = $this->textParser->getSiteUrl() . $node->getRoute($this->textParser->getLocale());
                 break;
             case NodeVariableParser::VARIABLE_NAME:
                 $value = $node->getName($this->textParser->getLocale());
                 break;
         }
         return $value;
     } elseif ($tokens[0] === 'node' && $tokens[1] === 'var' && $numTokens > 2) {
         $value = $node->getEntry();
         for ($i = 2; $i < $numTokens; $i++) {
             $value = $this->reflectionHelper->getProperty($value, $tokens[$i]);
             if ($value === null) {
                 break;
             }
         }
     } elseif ($tokens[0] === 'entry') {
         // lookup entry node
         $modelName = ucfirst($tokens[1]);
         $entryId = $tokens[2];
         $nodes = $this->nodeModel->getNodes($node->getRootNodeId(), $node->getRevision());
         foreach ($nodes as $node) {
             if ($node->getType() !== EntryNodeType::NAME || $node->getEntryModel() !== $modelName || $node->getEntryId() !== $entryId) {
                 continue;
             }
             $locale = isset($tokens[4]) ? $tokens[4] : $this->textParser->getLocale();
             switch ($tokens[3]) {
                 case NodeVariableParser::VARIABLE_URL:
                     $value = $this->textParser->getSiteUrl() . $node->getRoute($locale);
                     break 2;
                 case NodeVariableParser::VARIABLE_NAME:
                     $value = $node->getName($locale);
                     break 2;
                 case NodeVariableParser::VARIABLE_LINK:
                     $value = '<a href="' . $this->textParser->getSiteUrl() . $node->getRoute($locale) . '">' . $node->getName($locale) . '</a>';
                     break 2;
             }
             break;
         }
     }
     return $value;
 }