cancel
Showing results for 
Search instead for 
Did you mean: 

Check if content file exist

mau
Champ in-the-making
Champ in-the-making
Hi,
I want to create a new file named 'my_new_file.html' in guest_home. It works if file not existed but it does not work if file existed.

      $nodes = $session->query($spacesStore, "PATH:\"app:company_home/app:guest_home\"");
      $contentNode = $nodes[0];

//???? How to verify if file exist????
      $newNode = $contentNode->createChild('cm_content', 'cm_contains', 'my_new_file.html');
      $contentData = new ContentData($newNode, 'cm:content');      
      $contentData->mimetype = 'text/html';
      $newNode->cm_name = $fileName;
      $newNode->cm_description = 'Page Description';
      $contentData->encoding = 'UTF-8';
      $contentData->content = '<html><head><tile>My test</title></head><body>Content of Test Page</body></html>';
      $newNode->cm_content = $contentData;
      $session->save();


Please tell me how to verify if content file is already existed in the folder.
Mau
3 REPLIES 3

mau
Champ in-the-making
Champ in-the-making
Hi,
I tried 2 query statements to get number of rows returned from session query as follows:
=====================================================================================
$nodes = $session->query($store, "PATH:\"app:company_home/app:guest_home\"");
print '<hr/>Query results of PATH:\"app:company_home/app:guest_home\":'.count($nodes).'<hr/>';
// This query returned 1 I guess because I have files in the folder guest_home (Alfresco-Tutorial.pdf and my_page.html)
=====================================================================================
$fnode = $session->query($store, "PATH:\"app:company_home/app:guest_home/cm:my_page.html\"");
print '<hr/>Query results of PATH:\"app:company_home/app:guest_home/cm:my_page.html\":'.count($fnode).'<hr/>';
// This query returned 0 even if I have a file my_page.html
=====================================================================================
Followings are the print out of result array for query 1:
Start BaseObject::resultSetToNodes:nrows=1
stdClass Object ( [rowIndex] => 0 [columns] => Array ( [0] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}title [isMultiValue] => [value] => Guest Home ) [1] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}modified [isMultiValue] => [value] => 2009-01-26T03:17:46.046+04:30 ) [2] => stdClass Object ( [name] => {http://www.alfresco.org/model/system/1.0}store-identifier [isMultiValue] => [value] => SpacesStore ) [3] => stdClass Object ( [name] => {http://www.alfresco.org/model/system/1.0}node-dbid [isMultiValue] => [value] => 26 ) [4] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}modifier [isMultiValue] => [value] => System ) [5] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}name [isMultiValue] => [value] => Guest Home ) [6] => stdClass Object ( [name] => {http://www.alfresco.org/model/system/1.0}store-protocol [isMultiValue] => [value] => workspace ) [7] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}created [isMultiValue] => [value] => 2009-01-26T03:17:45.671+04:30 ) [8] => stdClass Object ( [name] => {http://www.alfresco.org/model/system/1.0}node-uuid [isMultiValue] => [value] => cd809b02-c338-4bd8-af61-22a629a0d38d ) [9] => stdClass Object ( [name] => {http://www.alfresco.org/model/application/1.0}icon [isMultiValue] => [value] => space-icon-default ) [10] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}creator [isMultiValue] => [value] => System ) [11] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}description [isMultiValue] => [value] => The guest root space ) [12] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}path [isMultiValue] => [value] => /{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/applicatio... ) ) [score] => 1 [node] => stdClass Object ( [id] => cd809b02-c338-4bd8-af61-22a629a0d38d [type] => {http://www.alfresco.org/model/content/1.0}folder [aspects] => Array ( [0] => {http://www.alfresco.org/model/application/1.0}uifacets [1] => {http://www.alfresco.org/model/content/1.0}auditable [2] => {http://www.alfresco.org/model/system/1.0}referenceable ) ) ) return:1
End BaseObject::resultSetToNodes
=====================================================================================
For query #2, there is no return

Any body could help me the description of return array from query. The document Is-it available? The return array come from what function of Alfresco? Any known bug from Alfresco server for this matter?
Thank you very much,
Mau

mau
Champ in-the-making
Champ in-the-making
Hi All,
When I make a query to Alfresco server using session query with query paths:
$node = $session->query($store, "PATH:\"app:company_home/app:guest_home/cm:my_page.html\"");
Whether the file exist or not, I do not see any value that could tell whether the file my_page.html is existed or not.
I do not see anywhere in this forum related to this subject. Do you have a way to check whether the file is existed on Alfresco server? I think it need to look into the server side because server does not returned or not returned the result correctly.
Any response will be appreciated.
Regards,
Mau

mau
Champ in-the-making
Champ in-the-making
Here is the print out I got by printing the result ($resultSet->rows) in function resultSetToNodes of BaseObject.php
Array (
[0] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}title [isMultiValue] => [value] => Guest Home )
[1] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}modified [isMultiValue] => [value] => 2009-01-26T03:17:46.046+04:30 )
[2] => stdClass Object ( [name] => {http://www.alfresco.org/model/system/1.0}store-identifier [isMultiValue] => [value] => SpacesStore )
[3] => stdClass Object ( [name] => {http://www.alfresco.org/model/system/1.0}node-dbid [isMultiValue] => [value] => 26 )
[4] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}modifier [isMultiValue] => [value] => System )
[5] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}name [isMultiValue] => [value] => Guest Home )
[6] => stdClass Object ( [name] => {http://www.alfresco.org/model/system/1.0}store-protocol [isMultiValue] => [value] => workspace ) [7] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}created [isMultiValue] => [value] => 2009-01-26T03:17:45.671+04:30 )
[8] => stdClass Object ( [name] => {http://www.alfresco.org/model/system/1.0}node-uuid [isMultiValue] => [value] => cd809b02-c338-4bd8-af61-22a629a0d38d )
[9] => stdClass Object ( [name] => {http://www.alfresco.org/model/application/1.0}icon [isMultiValue] => [value] => space-icon-default )
[10] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}creator [isMultiValue] => [value] => System )
[11] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}description [isMultiValue] => [value] => The guest root space )
[12] => stdClass Object ( [name] => {http://www.alfresco.org/model/content/1.0}path [isMultiValue] => [value] => /{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/applicatio... )