Skip to content

Commit 0c18156

Browse files
committed
Adjusting add location operation
1 parent c7ec49a commit 0c18156

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

classes/lib.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ function importAttribute( $data, &$contentObjectAttribute )
9595
function addNodeAssignment( $content_object, $parent_node_id, $set_as_main_node = false )
9696
{
9797
$main_node_id = $content_object->attribute( 'main_node_id' );
98-
$insertedNode =& $content_object->addLocation( $parent_node_id, true );
98+
$insertedNode = $content_object->addLocation( $parent_node_id, true );
9999
// Now set it as published and fix main_node_id
100100
$insertedNode->setAttribute( 'contentobject_is_published', 1 );
101-
$contentObject = eZContentObject::fetch( $objectID );
102-
$parentContentObject = eZContentObject::fetchByNodeID( $parentMainNodeID );
101+
$parentContentObject = eZContentObject::fetchByNodeID( $parent_node_id );
103102
if ( $set_as_main_node )
104103
{
105104
$main_node_id = $insertedNode->attribute( 'node_id' );

operations/nodeassignlocations.php

+15-9
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ function getHelpText()
77
{
88
return '
99
--operation="nodeassignlocations;locations=<node_id,node_id...>"
10-
11-
locations - a colon separated list of new parent nodes to assign to this node
10+
11+
Add new locations under the specified parent node id\'s
12+
locations - a colon separated list of new parent node id\'s to assign to this node
1213
';
1314
}
1415

@@ -35,19 +36,24 @@ function setParameters( $parm_array )
3536

3637
// Assign locations to the given node
3738
// locations - an array of node IDs for new parent nodes
38-
function runOperation( &$object )
39+
function runOperation( &$node )
3940
{
40-
$result = true;
41-
42-
require_once( 'kernel/classes/ezcontentobject.php' );
41+
$db = eZDB::instance();
42+
$db->begin();
4343

4444
foreach ($this->locations as $location)
4545
{
46-
$contentobject = $object->object();
47-
$result = $result && $contentobject->AddLocation( $location, true );
46+
$contentobject = $node->object();
47+
$id = $contentobject->addLocation( $location, true );
48+
if ( empty( $id ) )
49+
{
50+
$db->rollback();
51+
return false;
52+
}
4853
}
4954

50-
return $result;
55+
$db->commit();
56+
return true;
5157
}
5258

5359
var $locations = array();

0 commit comments

Comments
 (0)