createAndPublishObject and image

Author Message

Philippe VINCENT-ROYOL

Monday 14 April 2008 6:39:15 am

Hello,

I try to create an import file but ive some problem with image file.

This is a partial code :

$upload = "/var/www/tmp/my_image.jpg";

$attributes_agenda = array( 	'titre' 	=> $rows[$i]["TITRE"],
					'lieu' 	=> $rows[$i]["LIEU"],
					'texte'	=> $rows[$i]["TEXTE"],
					'date' 	=> $rows[$i]["DATE"],
					'date_fin' => $rows[$i]["DATE_FIN"],
					'image' 	=> $upload
				);
$params = array();
$params['creator_id'] = 14;
$params['parent_node_id'] = $nodeID;
$params['class_identifier'] = 'agenda_formation';
$params['attributes'] = $attributes_agenda;

$object = eZContentFunctions::createAndPublishObject( $params );


My "agenda_formation" class have an image attribute but it doesn't work. All text variable work perfectly..
I've someone have an idea..

Thanks :)
Philippe

Certified Developer (4.1): http://auth.ez.no/certification/verify/272607
Certified Developer (4.4): http://auth.ez.no/certification/verify/377321

G+ : http://plus.tl/dspe
Twitter : http://twitter.com/dspe

Philippe VINCENT-ROYOL

Tuesday 15 April 2008 7:21:30 am

UPDATE!

Now i dont have error but files are not copied ! I see filename, mime_type, original_filename on ezbinaryfile table.

So my question is .... with eZcontentFunctions::createAndPublishObject() must i create/use some function to move files on storage directory ?

Thanks

Certified Developer (4.1): http://auth.ez.no/certification/verify/272607
Certified Developer (4.4): http://auth.ez.no/certification/verify/377321

G+ : http://plus.tl/dspe
Twitter : http://twitter.com/dspe

Kristof Coomans

Tuesday 15 April 2008 7:51:25 am

Hi Philippe

Which version of eZ Publish are you using?
And do you get any errors/warnings when you run the script (I presume you are using a command line script) with the debug output enabled?
And which datatype are you using now, image or binary file?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Philippe VINCENT-ROYOL

Tuesday 15 April 2008 8:32:51 am

Hi Kristof

I m using ezpublish 3.9.2
I've forget to add permission on storage directory ! I m using image and binary file.. my class looks like this :

titre : text line
lieu : text line
texte : text block
date : datetime
date_fin : datetime
image : image (via upload)
fichier : file (via upload)

Now i find my binary file and can download it.. but its strange.. the debug outpout show, for example:

SELECT id, contentobject_attribute_id, filepath
                    FROM   ezimagefile
WHERE  filepath='var/nfs/hopital/storage/images-versioned/28290/1-fre-FR/formation_des_administrateurs_des_etablissements_sanitaires_sociaux_et_medico_sociaux1.jpg'

But directorty "images-versioned" don't exists.. and storage have a good permission..

Certified Developer (4.1): http://auth.ez.no/certification/verify/272607
Certified Developer (4.4): http://auth.ez.no/certification/verify/377321

G+ : http://plus.tl/dspe
Twitter : http://twitter.com/dspe

Philippe VINCENT-ROYOL

Wednesday 16 April 2008 5:08:05 am

I find the problem... i forget to install php4-imagemagic and imagemagick package on debian system .. that's why i didn't see image on back office :/

Now the last step is to add more file ;)

Thanks for your help !
Philippe

Certified Developer (4.1): http://auth.ez.no/certification/verify/272607
Certified Developer (4.4): http://auth.ez.no/certification/verify/377321

G+ : http://plus.tl/dspe
Twitter : http://twitter.com/dspe

Philippe VINCENT-ROYOL

Thursday 17 April 2008 2:32:46 am

Now i continue ^^

The last step is to add more file. I've try to use eZContentFunctions::createAndPublishObject( $params ); to add more file but don't find a solution.

so i've add this :

$object = eZContentFunctions::createAndPublishObject( $params );
		
if($fichier2 != "")
{
	include_once("kernel/classes/datatypes/ezbinaryfile/ezbinaryfile.php");
	include_once("lib/ezutils/classes/ezmimetype.php");
	include_once("lib/ezutils/classes/ezdir.php");
				
	$contentObjectAttributes =& $object->contentObjectAttributes();
			
	$attributeValue = $rows[$i]["FIC2_NOM"];
	$contentObjectAttributes[1]->setAttribute('binary_file', $attributeValue);
	$contentObjectAttributes[1]->store();
				
	$contentObjectAttribute =& $contentObjectAttributes[1];
			
	$contentObjectAttributeID = $contentObjectAttribute->attribute("id");
	$version = $contentObjectAttribute->attribute("version");
				
	$file =& eZBinaryFile::create($contentObjectAttributeID, $version);
				
	$file->setAttribute("contentobject_attribute_id", $contentObjectAttributeID);
	$file->setAttribute("version", $version);
	$file->setAttribute("filename", $rows[$i]["FIC2_NOM"]);
	$file->setAttribute("original_filename", $rows[$i]["FIC2_NOM"]);
				
	$mimeObj = new eZMimeType();
	$mime = $mimeObj->mimeTypeFor( false, $rows[$i]["FIC2_NOM"]);
			
	$file->setAttribute("mime_type", $mime);
	$file->store();
				
	$sys =& eZSys::instance();
	$storage_dir = $sys->storageDirectory();
				
	list($subdir, $extension) = split("/",$mime);
	$file_dir = $storage_dir.'/'."original/".$subdir;
	if(!file_exists($file_dir))
	{
		eZDir::mkdir($file_dir,0777,true);
	}
	$source_file = $storage_dir."/temp/".$rows[$i]["FIC2_NOM"];
	$target_file = $storage_dir."/original/".$subdir."/".$rows[$i]["FIC2_NOM"];
	copy($source_file,$target_file);
				
}

So , eZpublish have insert lines on ezbinaryfile table but when i want to see on back office the node.. it show only the first file :/

Thanks in advance,
Philippe

Certified Developer (4.1): http://auth.ez.no/certification/verify/272607
Certified Developer (4.4): http://auth.ez.no/certification/verify/377321

G+ : http://plus.tl/dspe
Twitter : http://twitter.com/dspe

Kristof Coomans

Thursday 17 April 2008 5:20:34 am

Hi Philippe

You can only store one file with a binary file attribute. If you want to attach multiple files to one object, I recommend you using multiple child nodes containing the files.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Philippe VINCENT-ROYOL

Friday 18 April 2008 2:24:16 am

Hi Kristof

Oops right .. sometimes i need to sleep ^^

Thanks again.

Certified Developer (4.1): http://auth.ez.no/certification/verify/272607
Certified Developer (4.4): http://auth.ez.no/certification/verify/377321

G+ : http://plus.tl/dspe
Twitter : http://twitter.com/dspe

Philippe VINCENT-ROYOL

Friday 18 April 2008 5:41:06 am

ok i promise this is the latest question !!

Source code was on a module. But i need to place it on a cronjob.

So i've create my_import.php file ..
this is the source code:

include_once( 'lib/ezutils/classes/ezcli.php' );

include_once( 'kernel/classes/ezscript.php' );


global $cli;


$cli =& eZCLI::instance();

$script =& eZScript::instance( array( 'description' => ( "Import  Database\n" .

                                                         "\n" .

                                                         "./bin/my_import.php" ),

                                      'debug-message' => '',
                                      'debug-output' => true,
                                      'use-session' => true,
                                      'use-module' => true,
                                      'use-extension' => true ) );



$script->startup();


$scriptOptions = $script->getOptions( "",

                                      "",

                                      array(),

                                      false,

                                      array( 'user' => true )

                                     );
                                     

$script->initialize();


include_once( 'lib/ezdb/classes/ezdb.php' );
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
include_once( 'kernel/classes/ezcontentfunctions.php' );

$params = array(	'server' => 'localhost',
			'user' => 'root',
			'password' => '',
			'database' => 'FHF',
			'use_slave_server' => 'false',
			'use_persistent_connection' => false
);

$db = eZDB::instance('ezmysql', $params, true);
		
$user = eZuser::fetch( 14 );
eZuser::setCurrentLyLoggedInUser( $user, $user->attribute( 'contentobject_id' ) );
		
$nodeID = "3051";		
$node = eZcontentObjectTreeNode::fetch( $nodeID );

$attribute_node = array( 'name' => 'test');
$param_node['creator_id'] = 14;
$param_node['parent_node_id'] = $nodeID;
$param_node['class_identifier'] = 'folder';
$param_node['attributes'] = $attribute_node;			
			
$object_node = eZContentFunctions::createAndPublishObject( $param_node );

$script->shutdown(0);

and i obtain this debug:

Fatal error: eZ publish did not finish its request
The execution of eZ publish was abruptly ended, the debug output is present below.
Notice: (eZMySQLDB::query(0.000 ms) query number per page:0)
SET NAMES 'utf8'

Error: (eZDebug::writeFile)
Cannot open log file 'var/log/notice.log' for writing
The web server must be allowed to modify the file.
File logging for 'var/log/notice.log' is disabled.

Error: (eZDebug::writeFile)
Cannot open log file 'var/log/error.log' for writing
The web server must be allowed to modify the file.
File logging for 'var/log/error.log' is disabled.

Notice: (eZMySQLDB::query(0.000 ms) query number per page:0)
SET NAMES 'utf8'

Warning: (PHP)
Invalid argument supplied for foreach() in /var/www/hopital.fr/hopital.hopital.fr/html/lib/ezutils/classes/ezmoduleoperationinfo.php on line 70

Error: (eZDebug::writeFile)
Cannot open log file 'var/log/warning.log' for writing
The web server must be allowed to modify the file.
File logging for 'var/log/warning.log' is disabled.

Warning: (PHP)
Undefined variable:  definitionFile in /var/www/hopital.fr/hopital.hopital.fr/html/lib/ezutils/classes/ezmoduleoperationinfo.php on line 77

Error: (eZModuleOperationInfo::loadDefinition)
Missing operation definition file for module: content

Error: (eZOperationHandler::execute)
Cannot execute operation 'publish' in module 'content', no valid data

No timing points defined
Group ini_load: 
Load cache: 0.0060 sec (2.5871%), 0.0010 avg sec (6)
FindInputFiles: 0.0022 sec (0.9720%), 0.0004 avg sec (6)
Group Mysql Total: 
Mysql_queries: 0.0135 sec (5.8531%), 0.0005 avg sec (30)
Looping result: 0.0007 sec (0.3210%), 0.0001 avg sec (13)
Group class_abstraction: 
Instantiating content class attribute: 0.0010 sec (0.4349%), 0.0001 avg sec (20)
Group General: 
String conversion: 0.0000 sec (0.0186%), 0.0000 avg sec (1)

Total script time: 0.2314 sec

I've forget to initialise something? It works on module and not here :/

Thanks in advance,
Philippe

Certified Developer (4.1): http://auth.ez.no/certification/verify/272607
Certified Developer (4.4): http://auth.ez.no/certification/verify/377321

G+ : http://plus.tl/dspe
Twitter : http://twitter.com/dspe

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 09:12:46
Script start
Timing: Jan 31 2025 09:12:46
Module start 'layout'
Timing: Jan 31 2025 09:12:46
Module start 'content'
Timing: Jan 31 2025 09:12:47
Module end 'content'
Timing: Jan 31 2025 09:12:47
Script end

Main resources:

Total runtime1.1969 sec
Peak memory usage4,096.0000 KB
Database Queries75

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0053 588.1484151.2109
Module start 'layout' 0.00530.0031 739.359436.6484
Module start 'content' 0.00841.1877 776.00781,059.4844
Module end 'content' 1.19600.0008 1,835.492231.8438
Script end 1.1969  1,867.3359 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00280.2354160.0002
Check MTime0.00110.0933160.0001
Mysql Total
Database connection0.00110.090910.0011
Mysqli_queries1.102492.1082750.0147
Looping result0.00060.0493730.0000
Template Total1.158496.820.5792
Template load0.00210.175620.0011
Template processing1.156396.608520.5782
Template load and register function0.00120.096310.0012
states
state_id_array0.00220.179710.0022
state_identifier_array0.00230.190720.0011
Override
Cache load0.00180.1490760.0000
Sytem overhead
Fetch class attribute can translate value0.00050.037820.0002
Fetch class attribute name0.00170.1421110.0002
XML
Image XML parsing0.00500.419620.0025
class_abstraction
Instantiating content class attribute0.00000.0033180.0000
General
dbfile0.00680.5685230.0003
String conversion0.00000.000440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
9content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
9content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
22content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
9content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 56
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs