Ejemplo n.º 1
0
    /**
     * Makes the following function attributes field attribtues, for testing purposes :
     *  - class_name
     *  - class_identifier
     *  - main_node_id
     *  - main_parent_node_id
     *
     * @return the overridden definition array
     */
    public static function definition()
    {
        $definitionOverride = array( 'fields' => array( 'class_name' =>
                                                            array( 'name' =>     "LocalClassName",
                                                                   'datatype' => 'mixed' ),
                                                        'class_identifier' =>
                                                            array( 'name' =>     "LocalClassIdentifier",
                                                                   'datatype' => 'mixed' ),
                                                        'main_node_id' =>
                                                            array( 'name' =>     "MainNodeId",
                                                                   'datatype' => 'mixed' ),
                                                        'main_parent_node_id' =>
                                                            array( 'name' =>     "MainParentNodeId",
                                                                   'datatype' => 'mixed' )
                                                      )
                                   );

        $definition = array_merge_recursive( parent::definition(), $definitionOverride );
        $definition['class_name'] = __CLASS__;

        unset( $definition['function_attributes']['class_name'] );
        unset( $definition['function_attributes']['class_identifier'] );
        unset( $definition['function_attributes']['main_node_id'] );
        unset( $definition['function_attributes']['main_parent_node_id'] );

        return $definition;
    }
Ejemplo n.º 2
0
 function fetchObjectListCount($sectionID, $status = false)
 {
     if ($status == 'archived') {
         $status = eZContentObject::STATUS_ARCHIVED;
     } else {
         $status = eZContentObject::STATUS_PUBLISHED;
     }
     $rows = eZPersistentObject::fetchObjectList(eZContentObject::definition(), array(), array('section_id' => $sectionID, 'status' => $status), false, null, false, false, array(array('operation' => 'count( id )', 'name' => 'count')));
     return array('result' => $rows[0]['count']);
 }
 /**
  * Unit test for {@link eZContentObject::fetchByNodeID()}
  */
 public function testFetchByNodeIDAsRow()
 {
     $fetchedObject = eZContentObject::fetchByNodeID(2, false);
     $def = eZContentObject::definition();
     self::assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $fetchedObject, "eZContentObject::fetchByNodeID() with \$asObject=false must return an array");
     foreach ($def['fields'] as $key => $fieldDef) {
         self::assertArrayHasKey($key, $fetchedObject, "eZContentObject::fetchByNodeID() with \$asObject=false must return an array with '{$key}' key");
     }
     $this->assertEquals('eZ Publish', $fetchedObject['name']);
 }
Ejemplo n.º 4
0
function importRSSItem($item, $rssImport, $cli, $channel)
{
    $rssImportID = $rssImport->attribute('id');
    $rssOwnerID = $rssImport->attribute('object_owner_id');
    // Get owner user id
    $parentContentObjectTreeNode = eZContentObjectTreeNode::fetch($rssImport->attribute('destination_node_id'));
    // Get parent treenode object
    if ($parentContentObjectTreeNode == null) {
        $cli->output('RSSImport ' . $rssImport->attribute('name') . ': Destination tree node seems to be unavailable');
        return 0;
    }
    $parentContentObject = $parentContentObjectTreeNode->attribute('object');
    // Get parent content object
    $titleElement = $item->getElementsByTagName('title')->item(0);
    $title = is_object($titleElement) ? $titleElement->textContent : '';
    // Test for link or guid as unique identifier
    $link = $item->getElementsByTagName('link')->item(0);
    $guid = $item->getElementsByTagName('guid')->item(0);
    $rssId = '';
    if ($link->textContent) {
        $rssId = $link->textContent;
    } elseif ($guid->textContent) {
        $rssId = $guid->textContent;
    } else {
        $cli->output('RSSImport ' . $rssImport->attribute('name') . ': Item has no unique identifier. RSS guid or link missing.');
        return 0;
    }
    $md5Sum = md5($rssId);
    // Try to fetch RSSImport object with md5 sum matching link.
    $existingObject = eZPersistentObject::fetchObject(eZContentObject::definition(), null, array('remote_id' => 'RSSImport_' . $rssImportID . '_' . $md5Sum));
    // if object exists, continue to next import item
    if ($existingObject != null) {
        $cli->output('RSSImport ' . $rssImport->attribute('name') . ': Object ( ' . $existingObject->attribute('id') . ' ) with ID: "' . $rssId . '" already exists');
        unset($existingObject);
        // delete object to preserve memory
        return 0;
    }
    // Fetch class, and create ezcontentobject from it.
    $contentClass = eZContentClass::fetch($rssImport->attribute('class_id'));
    // Instantiate the object with user $rssOwnerID and use section id from parent. And store it.
    $contentObject = $contentClass->instantiate($rssOwnerID, $parentContentObject->attribute('section_id'));
    $db = eZDB::instance();
    $db->begin();
    $contentObject->store();
    $contentObjectID = $contentObject->attribute('id');
    // Create node assignment
    $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObjectID, 'contentobject_version' => $contentObject->attribute('current_version'), 'is_main' => 1, 'parent_node' => $parentContentObjectTreeNode->attribute('node_id')));
    $nodeAssignment->store();
    $version = $contentObject->version(1);
    $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
    $version->store();
    // Get object attributes, and set their values and store them.
    $dataMap = $contentObject->dataMap();
    $importDescription = $rssImport->importDescription();
    // Set content object attribute values.
    $classAttributeList = $contentClass->fetchAttributes();
    foreach ($classAttributeList as $classAttribute) {
        $classAttributeID = $classAttribute->attribute('id');
        if (isset($importDescription['class_attributes'][$classAttributeID])) {
            if ($importDescription['class_attributes'][$classAttributeID] == '-1') {
                continue;
            }
            $importDescriptionArray = explode(' - ', $importDescription['class_attributes'][$classAttributeID]);
            if (count($importDescriptionArray) < 1) {
                $cli->output('RSSImport ' . $rssImport->attribute('name') . ': Invalid import definition. Please redit.');
                break;
            }
            $elementType = $importDescriptionArray[0];
            array_shift($importDescriptionArray);
            switch ($elementType) {
                case 'item':
                    setObjectAttributeValue($dataMap[$classAttribute->attribute('identifier')], recursiveFindRSSElementValue($importDescriptionArray, $item));
                    break;
                case 'channel':
                    setObjectAttributeValue($dataMap[$classAttribute->attribute('identifier')], recursiveFindRSSElementValue($importDescriptionArray, $channel));
                    break;
            }
        }
    }
    $contentObject->setAttribute('remote_id', 'RSSImport_' . $rssImportID . '_' . $md5Sum);
    $contentObject->store();
    $db->commit();
    // Publish new object. The user id is sent to make sure any workflow
    // requiring the user id has access to it.
    $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObject->attribute('id'), 'version' => 1, 'user_id' => $rssOwnerID));
    if (!isset($operationResult['status']) || $operationResult['status'] != eZModuleOperationInfo::STATUS_CONTINUE) {
        if (isset($operationResult['result']) && isset($operationResult['result']['content'])) {
            $failReason = $operationResult['result']['content'];
        } else {
            $failReason = "unknown error";
        }
        $cli->error("Publishing failed: {$failReason}");
        unset($failReason);
    }
    $db->begin();
    unset($contentObject);
    unset($version);
    $contentObject = eZContentObject::fetch($contentObjectID);
    $version = $contentObject->attribute('current');
    // Set object Attributes like modified and published timestamps
    $objectAttributeDescription = $importDescription['object_attributes'];
    foreach ($objectAttributeDescription as $identifier => $objectAttributeDefinition) {
        if ($objectAttributeDefinition == '-1') {
            continue;
        }
        $importDescriptionArray = explode(' - ', $objectAttributeDefinition);
        $elementType = $importDescriptionArray[0];
        array_shift($importDescriptionArray);
        switch ($elementType) {
            default:
            case 'item':
                $domNode = $item;
                break;
            case 'channel':
                $domNode = $channel;
                break;
        }
        switch ($identifier) {
            case 'modified':
                $dateTime = recursiveFindRSSElementValue($importDescriptionArray, $domNode);
                if (!$dateTime) {
                    break;
                }
                $contentObject->setAttribute($identifier, strtotime($dateTime));
                $version->setAttribute($identifier, strtotime($dateTime));
                break;
            case 'published':
                $dateTime = recursiveFindRSSElementValue($importDescriptionArray, $domNode);
                if (!$dateTime) {
                    break;
                }
                $contentObject->setAttribute($identifier, strtotime($dateTime));
                $version->setAttribute('created', strtotime($dateTime));
                break;
        }
    }
    $version->store();
    $contentObject->store();
    $db->commit();
    $cli->output('RSSImport ' . $rssImport->attribute('name') . ': Object created; ' . $title);
    return 1;
}
Ejemplo n.º 5
0
                $objectList = eZPersistentObject::fetchObjectList(eZContentObject::definition(), null, array('id' => $deleteID), null, null, true);
                foreach ($objectList as $object) {
                    $object->purge();
                }
            }
        } else {
            return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel');
        }
    }
} else {
    if ($http->hasPostVariable('EmptyButton')) {
        $access = $user->hasAccessTo('content', 'cleantrash');
        if ($access['accessWord'] == 'yes' || $access['accessWord'] == 'limited') {
            while (true) {
                // Fetch 100 objects at a time, to limit transaction size
                $objectList = eZPersistentObject::fetchObjectList(eZContentObject::definition(), null, array('status' => eZContentObject::STATUS_ARCHIVED), null, 100, true);
                if (count($objectList) < 1) {
                    break;
                }
                foreach ($objectList as $object) {
                    $object->purge();
                }
            }
        } else {
            return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel');
        }
    }
}
$tpl = eZTemplate::factory();
$tpl->setVariable('view_parameters', $viewParameters);
$Result = array();
 /**
  * Returns the number of content objects with the content class id $contentClassID
  *
  * @param int $contentClassID
  * @return int
  */
 static function fetchSameClassListCount( $contentClassID )
 {
     $result = eZPersistentObject::fetchObjectList( eZContentObject::definition(),
                                                    array(),
                                                    array( "contentclass_id" => $contentClassID ),
                                                    false, null,
                                                    false, false,
                                                    array( array( 'operation' => 'count( * )',
                                                                  'name' => 'count' ) ) );
     return $result[0]['count'];
 }
Ejemplo n.º 7
0
 /**
  * Test for eZContentObject::fetchListCount(), using content object ID + archived status
  */
 public function testFetchListCountOnObjectIDAndArchivedStatus()
 {
     $this->article->setAttribute('status', eZContentObject::STATUS_ARCHIVED);
     $this->article->store();
     $eZContentObjectDefinition = eZContentObject::definition();
     $count = eZContentObject::fetchListCount(array($eZContentObjectDefinition['name'] . ".id" => $this->article->id, 'status' => eZContentObject::STATUS_ARCHIVED));
     $this->assertEquals(1, $count);
 }
}

$nonUniqueRemoteIDDataListCount = count( $nonUniqueRemoteIDDataList );

$cli->output( '' );
$cli->output( "Found $nonUniqueRemoteIDDataListCount content objects with empty remote IDs." );
$cli->output( '' );

if ( $nonUniqueRemoteIDDataListCount )
{
    $cli->output( 'Fixing', false );

    foreach ( $nonUniqueRemoteIDDataList as $nonUniqueRemoteIDData )
    {
        // fetch objects with eZPersistentObject to avoid object cache
        $contentObjects = eZPersistentObject::fetchObjectList( eZContentObject::definition(),
                                                               null,
                                                               array( 'id' => $nonUniqueRemoteIDData['id'] ),
                                                               array( 'status' => 'desc', 'published' => 'asc' ) );
        foreach ( $contentObjects as $i => $contentObject )
        {
            $contentObject->setAttribute( 'remote_id', eZRemoteIdUtility::generate( 'object' ) );
            $contentObject->store();
        }

        ++$totalCount;
        $cli->output( '.', false );
    }
}

$cli->output( '' );
Ejemplo n.º 9
0
    }
    $db = eZDB::instance($dbImpl, $params, true);
    eZDB::setInstance($db);
}
$db->setIsSQLOutputEnabled($showSQL);
$searchEngine = eZSearch::getEngine();
if (!$searchEngine instanceof ezpSearchEngine) {
    $cli->error("The configured search engine does not implement the ezpSearchEngine interface or can't be found.");
    $script->shutdown(1);
}
if ($cleanupSearch) {
    $cli->output("{eZSearchEngine: Cleaning up search data", false);
    $searchEngine->cleanup();
    $cli->output("}");
}
$def = eZContentObject::definition();
$conds = array('status' => eZContentObject::STATUS_PUBLISHED);
$count = eZPersistentObject::count($def, $conds, 'id');
$cli->output("Number of objects to index: {$count}");
$length = 50;
$limit = array('offset' => 0, 'length' => $length);
$script->resetIteration($count);
$needRemoveWithUpdate = $searchEngine->needRemoveWithUpdate();
do {
    // clear in-memory object cache
    eZContentObject::clearCache();
    $objects = eZPersistentObject::fetchObjectList($def, null, $conds, null, $limit);
    foreach ($objects as $object) {
        if ($needRemoveWithUpdate || !$cleanupSearch) {
            $searchEngine->removeObjectById($object->attribute("id"), false);
        }
Ejemplo n.º 10
0
 function canBeRemoved($sectionID = false)
 {
     if ($sectionID === false) {
         $sectionID = $this->attribute('id');
     }
     $objects = eZPersistentObject::fetchObjectList(eZContentObject::definition(), null, array('section_id' => $sectionID));
     $limitations = eZPolicyLimitation::findByType('Section', $sectionID, true, false);
     $userRoles = eZRole::fetchRolesByLimitation('section', $sectionID);
     if (count($objects) > 0 or count($limitations) > 0 or count($userRoles) > 0) {
         return false;
     } else {
         return true;
     }
 }
Ejemplo n.º 11
0
 /**
  * Check if the object that contains the ezpaex attribute is an user
  *
  * @return bool if the contentobject is a user or not
  */
 function isUser()
 {
     $ezpo = eZPersistentObject::fetchObject(eZContentObject::definition(), null, array('id' => $this->attribute('contentobject_id')), true);
     return eZUser::isUserObject($ezpo);
 }
        $contentObject->store();
    }
    $totalCount += $nonUniqueRemoteIDData['cnt'] - 1;
    $cli->output('');
    $cli->output('');
}
if ($db->databaseName() == 'oracle') {
    $nonUniqueRemoteIDDataList = $db->arrayQuery("SELECT id FROM ezcontentobject WHERE remote_id IS NULL");
} else {
    $nonUniqueRemoteIDDataList = $db->arrayQuery("SELECT id FROM ezcontentobject WHERE remote_id = ''");
}
$nonUniqueRemoteIDDataListCount = count($nonUniqueRemoteIDDataList);
$cli->output('');
$cli->output("Found {$nonUniqueRemoteIDDataListCount} content objects with empty remote IDs.");
$cli->output('');
if ($nonUniqueRemoteIDDataListCount) {
    $cli->output('Fixing', false);
    foreach ($nonUniqueRemoteIDDataList as $nonUniqueRemoteIDData) {
        // fetch objects with eZPersistentObject to avoid object cache
        $contentObjects = eZPersistentObject::fetchObjectList(eZContentObject::definition(), null, array('id' => $nonUniqueRemoteIDData['id']), array('status' => 'desc', 'published' => 'asc'));
        foreach ($contentObjects as $i => $contentObject) {
            $contentObject->setAttribute('remote_id', eZRemoteIdUtility::generate('object'));
            $contentObject->store();
        }
        ++$totalCount;
        $cli->output('.', false);
    }
}
$cli->output('');
$cli->output("Number of content objects that received a new remote ID : {$totalCount}");
$script->shutdown(0);
Ejemplo n.º 13
0
 function attribute($attr)
 {
     switch ($attr) {
         case 'sections':
             $sections = eZSection::fetchList(false);
             foreach ($sections as $key => $section) {
                 $sections[$key]['Name'] = $section['name'];
                 $sections[$key]['value'] = $section['id'];
             }
             return $sections;
             break;
         case 'languages':
             return eZContentLanguage::fetchList();
             break;
         case 'usergroups':
             $groups = eZPersistentObject::fetchObjectList(eZContentObject::definition(), array('id', 'name'), array('contentclass_id' => 3, 'status' => eZContentObject::STATUS_PUBLISHED), null, null, false);
             foreach ($groups as $key => $group) {
                 $groups[$key]['Name'] = $group['name'];
                 $groups[$key]['value'] = $group['id'];
             }
             return $groups;
             break;
         case 'contentclass_list':
             $classes = eZContentClass::fetchList(eZContentClass::VERSION_STATUS_DEFINED, true, false, array('name' => 'asc'));
             $classList = array();
             for ($i = 0; $i < count($classes); $i++) {
                 $classList[$i]['Name'] = $classes[$i]->attribute('name');
                 $classList[$i]['value'] = $classes[$i]->attribute('id');
             }
             return $classList;
             break;
         case 'workflow_list':
             $workflows = eZWorkflow::fetchList();
             $workflowList = array();
             for ($i = 0; $i < count($workflows); $i++) {
                 $workflowList[$i]['Name'] = $workflows[$i]->attribute('name');
                 $workflowList[$i]['value'] = $workflows[$i]->attribute('id');
             }
             return $workflowList;
             break;
     }
     return eZWorkflowEventType::attribute($attr);
 }
$script->startup();
$options = $script->getOptions('[class:]', '', array('class' => 'Identificatore della classe'));
$script->initialize();
$script->setUseDebugAccumulators(true);
$cli = eZCLI::instance();
try {
    if (isset($options['class'])) {
        $classIdentifier = $options['class'];
    } else {
        throw new Exception("Specificare la classe");
    }
    $class = eZContentClass::fetchByIdentifier($classIdentifier);
    if (!$class instanceof eZContentClass) {
        throw new Exception("Classe {$classIdentifier} non trovata");
    }
    $objects = eZPersistentObject::fetchObjectList(eZContentObject::definition(), array('id'), array('contentclass_id' => $class->attribute('id')), null, null, false);
    $ids = array();
    foreach ($objects as $object) {
        $ids[] = $object['id'];
    }
    $pendingAction = 'rename';
    if (count($ids) > 0) {
        $count = count($ids);
        $output = new ezcConsoleOutput();
        $progressBarOptions = array('emptyChar' => ' ', 'barChar' => '=');
        $progressBarOptions['minVerbosity'] = 10;
        $progressBar = new ezcConsoleProgressbar($output, intval($count), $progressBarOptions);
        $progressBar->start();
        foreach ($ids as $id) {
            $progressBar->advance();
            eZDB::instance()->query("INSERT INTO ezpending_actions( action, param ) VALUES ( '{$pendingAction}', '{$id}' )");
Ejemplo n.º 15
0
    $cli->output("Invalid parent tag.");
    $script->shutdown(1);
}
$cli->warning("This script will NOT republish objects, but rather update the CURRENT");
$cli->warning("version of published objects. If you do not wish to do that, you have");
$cli->warning("15 seconds to cancel the script! (press Ctrl-C)\n");
sleep(15);
$sourceClassAttributeIdentifier = $sourceClassAttribute->attribute('identifier');
$destClassAttributeIdentifier = $destClassAttribute->attribute('identifier');
$isDestClassAttributeTranslatable = (bool) $destClassAttribute->attribute('can_translate');
$adminUser = eZUser::fetchByName('admin');
$adminUser->loginCurrent();
$db = eZDB::instance();
$offset = 0;
$limit = 50;
$objectCount = eZPersistentObject::count(eZContentObject::definition(), array('contentclass_id' => $sourceClassAttribute->attribute('contentclass_id'), 'status' => eZContentObject::STATUS_PUBLISHED));
while ($offset < $objectCount) {
    $objects = eZContentObject::fetchFilteredList(array('contentclass_id' => $sourceClassAttribute->attribute('contentclass_id'), 'status' => eZContentObject::STATUS_PUBLISHED), $offset, $limit);
    foreach ($objects as $object) {
        foreach ($object->availableLanguages() as $languageCode) {
            $object->fetchDataMap(false, $languageCode);
        }
        if (isset($object->DataMap[$object->attribute('current_version')])) {
            $db->begin();
            $languageDataMap = $object->DataMap[$object->attribute('current_version')];
            $initialLanguageCode = $object->initialLanguageCode();
            // first convert the initial (main) language
            $objectAttributes = $languageDataMap[$initialLanguageCode];
            if (isset($objectAttributes[$sourceClassAttributeIdentifier]) && isset($objectAttributes[$destClassAttributeIdentifier])) {
                $sourceObjectAttribute = $objectAttributes[$sourceClassAttributeIdentifier];
                $destObjectAttribute = $objectAttributes[$destClassAttributeIdentifier];
$scriptVerboseLevel = isset($options['script-verbose-level']) ? $options['script-verbose-level'] : 1;
$troubleshoot = isset($options['script-verbose-level']) && $options['script-verbose-level'] > 0 ? true : false;
$objectIDs = isset($options['object-ids']) && strlen($options['object-ids']) >= 1 ? explode(',', $options['object-ids']) : false;
$attributeIdentifiers = isset($options['attribute-identifiers']) && strlen($options['attribute-identifiers']) >= 1 ? explode(',', $options['attribute-identifiers']) : array('image');
$version = isset($options['version']) && strlen($options['version']) >= 1 ? $options['version'] : 'current';
$test = isset($options['test-only']) ? true : false;
$showSQL = isset($options['sql']) ? true : false;
/** Script default values **/
$adminUserID = 14;
$objectVersionsModified = array();
$offset = 0;
$limit = 1;
$status = true;
$resultCounter = 1;
$asObject = true;
$contentObjectDefinition = eZContentObject::definition();
$contentObjectVersionDefinition = eZContentObjectVersion::definition();
$contentObjectDefinitionContentObjectID = $contentObjectDefinition['name'] . '.id';
$contentObjectVersionDefinitionContentObjectID = $contentObjectVersionDefinition['name'] . '.id';
$conditions = null;
$customConds = ' WHERE ';
$countCustomConds = $customConds;
if ($version == 'current' || $version == 'new') {
    $queryContentObjectXDefinition = $contentObjectDefinition;
    $queryContentObjectXDefinitionContentObjectID = $contentObjectDefinitionContentObjectID;
    $objectTypeName = 'objects';
    $objectTypeVersionName = "{$version} version";
} elseif ($version == 'all') {
    $queryContentObjectXDefinition = $contentObjectVersionDefinition;
    $contentObjectVersionDefinitionContentObjectIDFieldName = str_replace('ez', '', $contentObjectDefinition['name']);
    $queryContentObjectXDefinitionContentObjectID = $contentObjectVersionDefinition['name'] . "." . $contentObjectVersionDefinitionContentObjectIDFieldName . '_id';