What's wrong with this code?

Author Message

Clemens T

Monday 03 October 2005 4:35:21 am

hey all!
I'm trying to add a binaryfile to a contentobjectattribute, here's my first attempt (doesn't work):

$attribs =& $contentObject->contentObjectAttributes();
for($i=0;$i<count($attribs);$i++){
	switch($attribs[$i]->attribute("contentclass_attribute_identifier")) {
		case 'commentaar':
			$attribs[$i]->setAttribute('data_text', $http->postVariable( 'commentaar' ) );
			$attribs[$i]->store();
		case 'bestand':
			include_once( 'lib/ezutils/classes/ezhttpfile.php' );

	        	if ( eZHTTPFile::canFetch( 'userfile') ){
		        	$file =& eZHTTPFile::fetch('userfile');
			  	$dir = eZSys::storageDirectory( );
	
		        	$mimeData = eZMimeType::findByFileContents( $file->attribute( 'original_filename' ) );
			  	$mimeCategory = $file['MimeCategory'];
			  	//$mime = explode( '/', $mimeData['name'] );
	           		//$file->store( false, false, $mimeData );
			 	print "mimeDataName:".$mimeData['name']."<br><br><br>";
				print "attributid:".$attribs[$i]->attribute( 'id' );
	            		$binary =& eZBinaryFile::create( $attribs[$i]->attribute( 'id' ), 1 );

	        		$binary->setAttribute( 'contentobject_attribute_id', $attribs[$i]->attribute( 'id' ) );
				$binary->setAttribute( 'version', $attribs[$i]->attribute( 'version' ) );
				$binary->setAttribute( 'filename', $file->attribute( 'original_filename'));
				$binary->setAttribute( 'original_filename', $file->attribute( 'original_filename'));
				$binary->setAttribute( 'mime_type', $mimeData['name'] );
				
				$binary->store( );
				print ("<br><br>binary:");
				var_dump($binary);

				$attribs[$i]->setContent( $binary );
				$attribs[$i]->store();
		   	}

		break;
	}
}

Any enhancement/suggestion/comment will do... hopefully I'll get there eventually!

Thanks a lot,
Clemens

*- pike

Thursday 02 November 2006 5:01:15 pm

Hoi Clemens

I was looking for something else when I bumped into kernel/classes/ezcontentupload.php

function handleUpload( &$result, $httpFileIdentifier, $location, $existingNode )

not exactly what you're looking for either; because it uses upload.ini to determine what object class to use for a mimetype, and then chooses its attribute itself. but it could help / aka the code you need might be in there ?

for example, I see
$status = $dataMap[$fileAttribute]->insertHTTPFile( $object, $publishVersion, eZContentObject::defaultLanguage(), $file, $mimeData, $storeResult );

oh, .. ok, .. insertHTTPFile looks like 99% your code :-) except for

  $db =& eZDB::instance();
  $db->begin();
   ....code
  $db->commit();

eh; dont know.

good luck!
*pike

---------------
The class eZContentObjectTreeNode does.

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 06:16:57
Script start
Timing: Jan 31 2025 06:16:57
Module start 'layout'
Timing: Jan 31 2025 06:16:57
Module start 'content'
Timing: Jan 31 2025 06:16:59
Module end 'content'
Timing: Jan 31 2025 06:16:59
Script end

Main resources:

Total runtime1.2335 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0048 588.1328151.2109
Module start 'layout' 0.00480.0029 739.343836.6484
Module start 'content' 0.00781.2250 775.9922891.1406
Module end 'content' 1.23280.0008 1,667.132812.1641
Script end 1.2335  1,679.2969 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.2536160.0002
Check MTime0.00130.1034160.0001
Mysql Total
Database connection0.00070.055510.0007
Mysqli_queries1.184696.0361540.0219
Looping result0.00070.0589520.0000
Template Total1.190696.520.5953
Template load0.00200.160320.0010
Template processing1.188696.355920.5943
Template load and register function0.00150.119010.0015
states
state_id_array0.00230.186910.0023
state_identifier_array0.00180.146220.0009
Override
Cache load0.00160.1324210.0001
Sytem overhead
Fetch class attribute can translate value0.00060.047920.0003
Fetch class attribute name0.00230.190220.0012
XML
Image XML parsing0.00030.021920.0001
class_abstraction
Instantiating content class attribute0.00000.000720.0000
General
dbfile0.00160.1329100.0002
String conversion0.00000.000740.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
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 17
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs