cancel
Showing results for 
Search instead for 
Did you mean: 

Getting past version of a node

dallinns
Champ on-the-rise
Champ on-the-rise
What would be the most effective/efficient route inside of PHP to find all of the past versions of a node? Is there a php function or rest service to access that?
3 REPLIES 3

ddanninger
Champ in-the-making
Champ in-the-making
Actually in the PHP Library there should be a Method called "getVersions" -> implemented in the VersionHistory.php

For rest there is also a url for that -> it must be http://localhost:8080/alfresco/service/api/version

just provide the nodeRef data on the GET Command

http://localhost:8080/alfresco/service/api/version?nodeRef=workspace://SpacesStore/0000-00000

I implemented this also in my PHP Library you can check it out on forge http://forge.alfresco.com/projects/ifresco-phplib/

In my Implementation it is:

$Version = new RESTVersion($repository,$store,$session);
$VersionResponse = $Version->GetVersionInfo($Node->getId());

dallinns
Champ on-the-rise
Champ on-the-rise
How would I go about actually getting the content of a past version?

ddanninger
Champ in-the-making
Champ in-the-making
Check the Node.php & Version.php & VersionHistory.php & ContentData.php

They have relations to each other…..

Code Example:


$repository = new Repository($repositoryUrl);
    $ticket = $repository->authenticate($userName, $password);
    $session = $repository->createSession($ticket);

    // Create a reference to the 'SpacesStore'
    $spacesStore = new SpacesStore($session);
   
    $nodeId = "0000-000000-0000-00-000";
   
   
    $Node = $session->getNode($spacesStore, $nodeId);
    if ($Node != null) {
        echo "GET SOAP VERSIONS:";
        $VersionHistory = $Node->getVersionHistory();
        $Versions = $VersionHistory->getVersions();

        if (count($Versions) > 0) {
            // GET CONTENT FOREACH VERSION
            foreach ($Versions as $VersionLabel => $Version) {
                $Content = $Version->cm_content;
                if ($Content instanceof ContentData) {
                    echo "Version: $VersionLabel => Filesize: {$Content->getSize()} | Encoding: {$Content->getEncoding()} <br>";
                    $Data = $Content->getContent();
                }
            }
        }
       
    }

Gets the ContentData for each Version so you could work with the $Data variable then. But if you wanna save the file or something like that there is a Method implemented in ContentData (readContentToFile instead of getContent)