Return the last draft saved.

@return Revision
510942
public function getLastSavedDraftRevision()
    {
        if (!empty($this->lastSavedDraft)) {
            return $this->lastSavedDraft;
        }

        $published = $this->publishedRevision;
        $staged = $this->stagedRevision;

        $arrayCollection = $this->revisions->toArray();

        /** @var \Rcm\Entity\Revision $revision */
        $revision = end($arrayCollection);

        if (empty($revision)) {
            return null;
        }

        $found = false;

        while (!$found) {
            if (empty($revision)) {
                break;
            } elseif (!empty($published)
                && $published->getRevisionId() == $revision->getRevisionId()
            ) {
                $found = false;
            } elseif (!empty($staged)
                && $staged->getRevisionId() == $revision->getRevisionId()
            ) {
                $found = false;
            } elseif ($revision->wasPublished()) {
                $found = false;
            } else {
                $found = true;
            }

            if (!$found) {
                $revision = prev($arrayCollection);
            }
        }

        return $this->lastSavedDraft = $revision;
    }
1170409
public static function current_archived_stage()
    {
        $parts = explode('.', Versioned::get_reading_mode());
        if (sizeof($parts) === 3 && $parts[0] == 'Archive') {
            return $parts[2];
        }
        return static::DRAFT;
    }
1251835
public function get_data() {
        $data = parent::get_data();
        if (!empty($data->saverubric)) {
            $data->status = gradingform_controller::DEFINITION_STATUS_READY;
        } else if (!empty($data->saverubricdraft)) {
            $data->status = gradingform_controller::DEFINITION_STATUS_DRAFT;
        }
        return $data;
    }
25466
public function getLastRead(): \DateTime
    {
        if ($this->caching == false) {
            return \DateTime::createFromFormat("F d Y H:i:s.", date("F d Y H:i:s.", fileatime($this->getAbsoluteFilePath())));
        }

        if ($this->lastRead == null) {
            $this->lastRead = \DateTime::createFromFormat("F d Y H:i:s.", date("F d Y H:i:s.", fileatime($this->getAbsoluteFilePath())));
        }

        return $this->lastRead;
    }
1286474
public function getLastRow()
    {
        if($this->last_row == null) {
            $this->last_row = (int) $this->getActiveSheet()->getHighestRow();
        }

        return $this->last_row;
    }
729091
public function getLastModified()
	{
		if ($this->lastModified == null) {
			$this->requestHead();
		}
		return $this->lastModified == null ? new \DateTime() : $this->lastModified;
	}
981079
public function getExtendedMetadata($revision = null)
	{
		// Without revision, use current info
		if (!isset($revision)) {
			return $this->info['extmetadata'];
		}

		// Obtain the properties of the revision
		if (($info = $this->getRevision($revision)) === null) {
			return null;
		}

		return $info['extmetadata'];
	}
541251
public function getCommonMetadata($revision = null)
	{
		// Without revision, use current info
		if (!isset($revision)) {
			return $this->info['commonmetadata'];
		}

		// Obtain the properties of the revision
		if (($info = $this->getRevision($revision)) === null) {
			return null;
		}

		return $info['commonmetadata'];
	}
1304386
public function getStatusTitle()
    {
        $statusTitle = '';
        if ($this->isOnDraftOnly()) {
            $statusTitle = _t(__CLASS__.'.DRAFT', 'Draft');
        } elseif ($this->isModifiedOnDraft()) {
            $statusTitle = _t(__CLASS__.'.MODIFIED', 'Modified');
        }
        return $statusTitle;
    }
1224401
private function getRevision($document)
    {
        $revision = null;

        if ($document instanceof Document) {
            $revision = $document->getRevision();
        }

        return $revision;
    }
380108
public InternalDocumentRevision getCurrentRevision() {
        for(DocumentRevisionNode n : leafs) {
            if(n.getData().isCurrent()) {
                return n.getData();
            }
        }
        throw new IllegalStateException("No current revision found.");
    }
43566
public function lastUpdatedDate() {
    $directory = $this->environment->getHooksDirectory();
    $hooks_file = "$directory/hooks_processed.php";
    if (file_exists($hooks_file)) {
      $timestamp = filemtime($hooks_file);
      return $timestamp;
    }
  }
843755
public function getLast()
    {
        $this->internalDataListUpdate();
        $count = sizeof($this->internalDataListData);
        if (isset($this->internalDataListData[$count - 1])) {
            return $this->internalDataListUpdateValueIfNeeded($this->internalDataListData, $count - 1);
        }
        return null;
    }
1183424
public function save( Revision $revision, EditInfo $editInfo = null ) {
		if( !$revision->getContent()->getData() instanceof EntityDocument ) {
			throw new RuntimeException( 'Can only save Content of EntityDocuments' );
		}

		/** @var Item|Property $entity */
		$entity = $revision->getContent()->getData();
		$serialized = $this->entitySerializer->serialize( $entity );

		$params = array(
			'data' => json_encode( $serialized )
		);

		$revId = $revision->getId();
		if( !is_null( $revId ) ) {
			$params['baserevid'] = $revId;
		}

		$entityId = $entity->getId();
		if( !is_null( $entityId ) ) {
			$params['id'] = $entityId->getSerialization();

			// Always clear so that removing elements is possible
			$params['clear'] = 'true';
			// Add more detail to the default "Cleared an entity" summary
			// Note: this is later overridden if a summary is provided in the EditInfo
			$params['summary'] = 'Edited a ' . $entity->getType();

		} else {
			$params['new'] = $entity->getType();
		}

		// If no editInfo is explicitly passed call back to the one in the revision?
		if( $editInfo === null ) {
			$editInfo = $revision->getEditInfo();
		}

		if( $editInfo->getBot() ) {
			$params['bot'] = true;
		}
		if( $editInfo->getMinor() ) {
			$params['minor'] = true;
		}
		$summary = $editInfo->getSummary();
		if( !empty( $summary ) ) {
			$params['summary'] = $summary;
		}

		$result = $this->api->postRequest( 'wbeditentity', $params, $editInfo );
		return $this->entityDeserializer->deserialize( $result['entity'] );
	}
468017
public function getRevisionById($revisionId)
    {
        $revision = $this->revisions->get($revisionId);

        if ($revision !== null) {
            return $revision; //We get here when rendering an unpublished page version
        }

        foreach ($this->revisions as $revision) {
            if ($revision->getRevisionId() === $revisionId) {
                return $revision; //We get here when publishing a new page version
            }
        }

        return null;
    }
88670
public function getLastPage()
    {
        return $this->hasResults() ? ceil($this->adapter->getTotalResults() / $this->limit) : $this->getFirstPage();
    }
991780
private function rollbackToRevision(Revision $revision) {
        if ($revision == null) {
            return null;
        }

        $current = $revision->revisioned;

        // delete the old revisions for this model if needed
        if($this->getConfigRollbackCleanup()) {
            $revisionsToDelete = $current->revisions()->where('id', '>=', $revision->id)->delete();
        }

        $current->fill($revision->old);
        $current->save();

        // reload the relations
        $current = $current->load('revisions');

        return $current;
    }