cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco and php

seopayane
Champ in-the-making
Champ in-the-making
Is it possible to fetch data in alfresco's repository in php only or a php service? i need help!!! if is possible how do we do it???
10 REPLIES 10

rjohnson
Star Contributor
Star Contributor
Yes there is a PHP wrapper for the CMIS extension which lets you do this (and much more). Go to the Apache Chemistry wen site and you can download it from there.

seopayane
Champ in-the-making
Champ in-the-making
I've downloaded it with the example as well, and when i try to run the script i get this error. please help!!


Notice: Undefined index: argv in C:\xampp\htdocs\Ma-Ali\alfresco.php on line 46

Notice: Undefined index: argv in C:\xampp\htdocs\Ma-Ali\alfresco.php on line 47

Notice: Undefined index: argv in C:\xampp\htdocs\Ma-Ali\alfresco.php on line 48

Notice: Undefined index: argv in C:\xampp\htdocs\Ma-Ali\alfresco.php on line 49

Notice: Undefined index: argv in C:\xampp\htdocs\Ma-Ali\alfresco.php on line 50
———————————————————————————-
here are the line

$repo_url = $_SERVER["argv"][1];
$repo_username = $_SERVER["argv"][2];
$repo_password = $_SERVER["argv"][3];
$repo_folder = $_SERVER["argv"][4];
$repo_new_folder = $_SERVER["argv"][5];
===================================================
error from php wrapper

Fatal error: Uncaught exception 'CmisRuntimeException' in C:\xampp\htdocs\Ma-Ali\cmis_repository_wrapper.php:114 Stack trace: #0 C:\xampp\htdocs\Ma-Ali\cmis_repository_wrapper.php(139): CMISRepositoryWrapper->convertStatusCode(0, false) #1 C:\xampp\htdocs\Ma-Ali\cmis_repository_wrapper.php(126): CMISRepositoryWrapper->doGet(NULL) #2 C:\xampp\htdocs\Ma-Ali\cmis_repository_wrapper.php(85): CMISRepositoryWrapper->connect(NULL, NULL, NULL, NULL) #3 C:\xampp\htdocs\Ma-Ali\cmis_repository_wrapper.php(659): CMISRepositoryWrapper->__construct(NULL, NULL, NULL, NULL, Array) #4 C:\xampp\htdocs\Ma-Ali\alfresco.php(52): CMISService->__construct(NULL, NULL, NULL) #5 {main} thrown in C:\xampp\htdocs\Ma-Ali\cmis_repository_wrapper.php on line 114
————————————————————————————–
line in php wrapper

function convertStatusCode($code, $message)
    {
        switch ($code) {
            case HTTP_BAD_REQUEST:
                return new CmisInvalidArgumentException($message, $code);
            case HTTP_NOT_FOUND:
                return new CmisObjectNotFoundException($message, $code);
            case HTTP_FORBIDDEN:
                return new CmisPermissionDeniedException($message, $code);
            case HTTP_METHOD_NOT_ALLOWED:
                return new CmisNotSupportedException($message, $code);
            case HTTP_CONFLICT:
                return new CmisConstraintException($message, $code);
            default:
         here=====>> return new CmisRuntimeException($message, $code);

rjohnson
Star Contributor
Star Contributor
I'm not sure which example script you have tried to run but based on the code you have shown you appear to trying create a new folder in the repository. You also appear to have omitted the command line arguments. You need to execute these scripts from the command line with commands like


php5 {the-script-name}.php {url-to-server} {username} {password} {a-folder-name} {a-new-folder-to-create}


{url-to-server} will likely be http://localhost:8080/alfresco/service/api/cmis clearly this depends on your installation
{username} well, start with admin until you get things working then you can make it a "normal" user but stay away from any script that will delete things whilst running as admin - just for your own safety.
{password} self explanatory
{a-folder-name} Create a test folder in the root of your repository - say mytestfolder. Send this
{a-new-folder-name} Send one you want to create e.g mynewfolder

Run it and you should get a new folder called mynewfolder within mytestfolder.

seopayane
Champ in-the-making
Champ in-the-making
what im actually wanna do is view the in from the repository in a drupal website.

rjohnson
Star Contributor
Star Contributor
Sorry, don't quite get what you want to see from within Drupal.

seopayane
Champ in-the-making
Champ in-the-making
i want to view the files and group them but their filename on a table in drupal. more like querying. i wanna do a search facility. 

akujenga
Champ in-the-making
Champ in-the-making

Hi

Did you manage to get a solution to this issue? I'm facing the same problem with Drupal 7.5.3 and Alfresco Community 5.2.

Any help would be greatly appreciated.

rjohnson
Star Contributor
Star Contributor
Below is an extract from a simple PHP script I wrote that finds all documents of a given type. It pulls back all the metadata which would include the name and the nodeRef. So you could easily show a lits and then when someone clicks on an item use the noderef to go fetch the content.


ini_set('display_errors', '1');
error_reporting(0);
include("config.php");
require_once ('cmis_repository_wrapper.php');

$repo_url = URL;
$repo_username = USERNAME;
$repo_password = PASSWORD;

//Check cmis service connect or not
try{
   $client = new CMISService($repo_url, $repo_username, $repo_password);
}catch (Exception $ec) {
   echo "Cmis connection issue";
   die;
}

$sysstartdate = mktime(0,0,0,6,1,2012); // start 1st June
$today = strtotime(date("Y-m-d"));
$ltthan = $sysstartdate;

try{
   do {
      $gtthan = $ltthan;
      $ltthan = strtotime(date("Y-m-d",$gtthan)." +1 month");
      $qstring = "select * from fgdt:adocumenttype where cmis:creationDate >= TIMESTAMP '" . date("Y-m-d", $gtthan) ."T00:00:00.000+00:00' and cmis:creationDate < TIMESTAMP '". date("Y-m-d", $ltthan) . "T00:00:00.000+00:00'";
      
      $objs = $client->query($qstring);
         try{
            foreach ($objs->objectList as $obj)
            {
                   //!!! YOUR CODE TO DO THINGS WITH THE METADATA HERE
            }
      }catch (Exception $e2) {
         //echo "Caught exception: ".$e2->getMessage()."\n";
      }
      
   } while ($ltthan < $today);
}
catch (Exception $e1) {
   echo "Caught exception: ".$e1->getMessage()."\n";
   die;
}


Note that the extract is in a loop and does the query month by month. This is because Lucene has a 1000 item results set limit which is silent, so you have to frame your query in such a way as to be sure you will not get more than 1000 items returned or you have to change the limit which is done via Alfresco configuration.

seopayane
Champ in-the-making
Champ in-the-making
is there somewhere i should edit in the cmis_repository_wrapper.php cos im getting a connection error from it.