Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用CMIS PHP将文件上载到Alfresco时如何进行文件版本控制_Php_Alfresco_Atom Feed_Cmis - Fatal编程技术网

使用CMIS PHP将文件上载到Alfresco时如何进行文件版本控制

使用CMIS PHP将文件上载到Alfresco时如何进行文件版本控制,php,alfresco,atom-feed,cmis,Php,Alfresco,Atom Feed,Cmis,我正在使用通过ATOM将文档从本地文件夹上载到Alfresco Community Edition 5.1。下面是我用来执行此操作的脚本: require_once ('cmis_repository_wrapper.php'); require_once ('cmis_service.php'); $repo_url = "http://127.0.0.1:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom"; $repo_us

我正在使用通过ATOM将文档从本地文件夹上载到Alfresco Community Edition 5.1。下面是我用来执行此操作的脚本:

require_once ('cmis_repository_wrapper.php');
require_once ('cmis_service.php');

$repo_url = "http://127.0.0.1:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom";
$repo_username = "user";
$repo_password = "pass";

$client = new CMISService($repo_url, $repo_username, $repo_password);

$repo_folder = "/alfrescoFolder";
$source_folder = "localFolder/";
$source_files = array_diff(scandir("$source_folder", 1), array('..', '.'));
$myfolder = $client->getObjectByPath($repo_folder);

foreach($source_files as $file)
{
    try
    {
        $upload = $client->createDocumentFromSource($myfolder->id, $file, "$source_folder/$file");
    }
    catch(Exception $e)
    {
        echo "Some error here.";
    }
}
如果Alfresco存储库中不存在文档,则该脚本工作正常,文档上传没有问题。例如,假设我在Alfresco存储库中有一个名为
example.txt
的文档,因此,如果我尝试从本地文件夹上载一个同名文档,我会收到一个CMIS约束异常。我不知道如何上传现有文档的新版本

这是我迄今为止尝试过的,但不起作用:

$objs = $client->getChildren($myfolder->id);

foreach($source_files as $file)
{
    foreach($objs->objectList as $obj)
    {
        if($obj->properties['cmis:name'] == $file)
        {
            try
            {
                $checkedout = $client->checkOut($obj->id);
                $client->checkIn($checkedout->id);
            }
            catch(Exception $e)
            {
                echo "Some error here.";
            }
        }
        else
        {
            try
            {
                $upload = $client->createDocumentFromSource($myfolder->id, $file, "$source_folder/$file", array('cmis:objectTypeId'=>'D:ex:document'));
            }
            catch(Exception $e)
            {
                echo "Some error here";
            }
        }
    }
}
我得到这个错误:

DEBUG: postEntry: myURL = http://127.0.0.1:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom/checkedoutDEBUG: postEntry: entry_template = {title} {SUMMARY} {CONTENT} {PROPERTIES} DEBUG: postEntry: properties_xml = b549c715-9a9d-427c-bd4b-c6ea29d222cb;1.0 DEBUG: postEntry: hash_values = Array ( [PROPERTIES] => b549c715-9a9d-427c-bd4b-c6ea29d222cb;1.0 [SUMMARY] => {summary} ) DEBUG: postEntry: post_value = b549c715-9a9d-427c-bd4b-c6ea29d222cb;1.0
有趣的是,文档实际上被锁定进行编辑,所以我真的不知道发生了什么。我也不知道签出然后签入文档是否就是我应该如何对文档进行版本设置

TL;DR


我希望能够指定我正在上载的文档是现有文档的新版本。有人知道我怎么做吗?

我不是CMIS方面的专家,但我认为这回答了问题。参见“jevon”中的答案,其中提供了一个示例和链接(参见“更新文档”部分)

我不是CMIS专家,但我认为这回答了问题。请参阅“jevon”中的答案,其中提供了一个示例和链接(请参阅“更新文档”部分)

Apache Chemistry网站上的列出了CMIS PHP客户端可以和不能执行的操作。当前不支持签出、签入和取消签出。我知道他们欢迎捐款

当然,底层CMIS规范支持它,因此您可以更新库以支持签出/签入,也可以使用原始绑定。

Apache Chemistry网站上的列出了CMIS PHP客户端可以和不能执行的操作。当前不支持签出、签入和取消签出。我知道他们欢迎捐款


当然,底层CMIS规范支持它,因此您可以更新库以支持签出/签入或使用原始绑定。

我最近发现了一种实现版本控制服务的替代方法,包括示例用法。我已经用它成功地解决了我在问题中发布的问题

编辑:添加附加信息。

因此,为了让版本控制工作起来,我使用了库中提供的示例代码。我使用的脚本可用于创建新文档以及更新和版本现有文档。这就是:

<?php

require_once(__DIR__ . '/../vendor/autoload.php');
if (!is_file(__DIR__ . '/conf/Configuration.php')) {
    die("Please add your connection credentials to the file \"" . __DIR__ . "/conf/Configuration.php\".\n");
} else {
    require_once(__DIR__ . '/conf/Configuration.php');
}

$major = (boolean) isset($argv[1]) ? $argv[1] : false;

$httpInvoker = new \GuzzleHttp\Client(
    array(
        'defaults' => array(
            'auth' => array(
                CMIS_BROWSER_USER,
                CMIS_BROWSER_PASSWORD
            )
        )
    )
);

$parameters = array(
    \Dkd\PhpCmis\SessionParameter::BINDING_TYPE => \Dkd\PhpCmis\Enum\BindingType::BROWSER,
    \Dkd\PhpCmis\SessionParameter::BROWSER_URL => CMIS_BROWSER_URL,
    \Dkd\PhpCmis\SessionParameter::BROWSER_SUCCINCT => false,
    \Dkd\PhpCmis\SessionParameter::HTTP_INVOKER_OBJECT => $httpInvoker,
);

$sessionFactory = new \Dkd\PhpCmis\SessionFactory();

// If no repository id is defined use the first repository
if (CMIS_REPOSITORY_ID === null) {
    $repositories = $sessionFactory->getRepositories($parameters);
    $repositoryId = $repositories[0]->getId();
} else {
    $repositoryId = CMIS_REPOSITORY_ID;
}

$parameters[\Dkd\PhpCmis\SessionParameter::REPOSITORY_ID] = $repositoryId;

$session = $sessionFactory->createSession($parameters);
$rootFolder = $session->getObject($session->createObjectId($session->getRootFolder()->getId()));

try {

    $document = null;
    $stream = \GuzzleHttp\Stream\Stream::factory(fopen($filePath, 'r'));
    foreach ($rootFolder->getChildren() as $child) {
        if ($child->getName() === $fileName) {
            $document = $child;
            break;
        }
    }

    if (!$document) {

        $properties = array(
            \Dkd\PhpCmis\PropertyIds::OBJECT_TYPE_ID => 'cmis:document',
            \Dkd\PhpCmis\PropertyIds::NAME => $fileName
        );

        $document = $session->createDocument($properties, $rootFolder, $stream);
        $document = $session->getObject($document);
    }

    $checkedOutDocumentId = $document->getVersionSeriesCheckedOutId();
    if ($checkedOutDocumentId) {
        $checkedOutDocumentId = $session->createObjectId($checkedOutDocumentId);
    } else {
        $checkedOutDocumentId = $document->checkOut();
    }

    $checkedInDocumentId = $session->getObject($checkedOutDocumentId)->checkIn(
        $major,
        array(
            \Dkd\PhpCmis\PropertyIds::DESCRIPTION => 'New description'
        ),
        $stream,
        'Comments'
    );


} catch (\Dkd\PhpCmis\Exception\CmisVersioningException $e) {
    echo "********* ERROR **********\n";
    echo $e->getMessage() . "\n";
    echo "**************************\n";
    exit();
}

我最近发现了一种实现版本控制服务的替代方案,包括示例用法。我已经用它成功地解决了我在问题中发布的问题

编辑:添加附加信息。

因此,为了让版本控制工作起来,我使用了库中提供的示例代码。我使用的脚本可用于创建新文档以及更新和版本现有文档。这就是:

<?php

require_once(__DIR__ . '/../vendor/autoload.php');
if (!is_file(__DIR__ . '/conf/Configuration.php')) {
    die("Please add your connection credentials to the file \"" . __DIR__ . "/conf/Configuration.php\".\n");
} else {
    require_once(__DIR__ . '/conf/Configuration.php');
}

$major = (boolean) isset($argv[1]) ? $argv[1] : false;

$httpInvoker = new \GuzzleHttp\Client(
    array(
        'defaults' => array(
            'auth' => array(
                CMIS_BROWSER_USER,
                CMIS_BROWSER_PASSWORD
            )
        )
    )
);

$parameters = array(
    \Dkd\PhpCmis\SessionParameter::BINDING_TYPE => \Dkd\PhpCmis\Enum\BindingType::BROWSER,
    \Dkd\PhpCmis\SessionParameter::BROWSER_URL => CMIS_BROWSER_URL,
    \Dkd\PhpCmis\SessionParameter::BROWSER_SUCCINCT => false,
    \Dkd\PhpCmis\SessionParameter::HTTP_INVOKER_OBJECT => $httpInvoker,
);

$sessionFactory = new \Dkd\PhpCmis\SessionFactory();

// If no repository id is defined use the first repository
if (CMIS_REPOSITORY_ID === null) {
    $repositories = $sessionFactory->getRepositories($parameters);
    $repositoryId = $repositories[0]->getId();
} else {
    $repositoryId = CMIS_REPOSITORY_ID;
}

$parameters[\Dkd\PhpCmis\SessionParameter::REPOSITORY_ID] = $repositoryId;

$session = $sessionFactory->createSession($parameters);
$rootFolder = $session->getObject($session->createObjectId($session->getRootFolder()->getId()));

try {

    $document = null;
    $stream = \GuzzleHttp\Stream\Stream::factory(fopen($filePath, 'r'));
    foreach ($rootFolder->getChildren() as $child) {
        if ($child->getName() === $fileName) {
            $document = $child;
            break;
        }
    }

    if (!$document) {

        $properties = array(
            \Dkd\PhpCmis\PropertyIds::OBJECT_TYPE_ID => 'cmis:document',
            \Dkd\PhpCmis\PropertyIds::NAME => $fileName
        );

        $document = $session->createDocument($properties, $rootFolder, $stream);
        $document = $session->getObject($document);
    }

    $checkedOutDocumentId = $document->getVersionSeriesCheckedOutId();
    if ($checkedOutDocumentId) {
        $checkedOutDocumentId = $session->createObjectId($checkedOutDocumentId);
    } else {
        $checkedOutDocumentId = $document->checkOut();
    }

    $checkedInDocumentId = $session->getObject($checkedOutDocumentId)->checkIn(
        $major,
        array(
            \Dkd\PhpCmis\PropertyIds::DESCRIPTION => 'New description'
        ),
        $stream,
        'Comments'
    );


} catch (\Dkd\PhpCmis\Exception\CmisVersioningException $e) {
    echo "********* ERROR **********\n";
    echo $e->getMessage() . "\n";
    echo "**************************\n";
    exit();
}

谢谢你,戴夫。您提到的链接围绕JavaAPI展开。不幸的是,我对Java一无所知。此外,据我所知,CMIS Java API的功能要比PHP丰富得多,所以我不知道Java示例对PHP有多适用。啊,抱歉-我应该更加注意你的问题。我与一位了解CMIS的同事进行了一次对话,他确认PHP客户端中没有实现版本控制服务。在规范级别上,您需要执行签出和签入操作,但在编写本文时,PHP客户端不支持这一操作。我必须找到其他方法来实现这一点。谢谢你的帮助。谢谢你,戴夫。您提到的链接围绕JavaAPI展开。不幸的是,我对Java一无所知。此外,据我所知,CMIS Java API的功能要比PHP丰富得多,所以我不知道Java示例对PHP有多适用。啊,抱歉-我应该更加注意你的问题。我与一位了解CMIS的同事进行了一次对话,他确认PHP客户端中没有实现版本控制服务。在规范级别上,您需要执行签出和签入操作,但在编写本文时,PHP客户端不支持这一操作。我必须找到其他方法来实现这一点。谢谢你的帮助。