/** * Helper function for testIssue16078(), based on ezpObject::addTranslation(). * * @param object $object * @param string $newLanguageCode * @return version in new language */ public function addTranslationDontPublish($object, $newLanguageCode) { // Make sure to refresh the objects data. $object->refresh(); $object->object->cleanupInternalDrafts(); $publishedDataMap = $object->object->dataMap(); $version = $object->object->createNewVersionIn($newLanguageCode, 'eng-GB'); // Create new translation based on eng-GB $version->setAttribute('status', eZContentObjectVersion::STATUS_INTERNAL_DRAFT); $version->store(); $newVersion = $object->object->version($version->attribute('version')); $newVersionAttributes = $newVersion->contentObjectAttributes($newLanguageCode); $versionDataMap = array(); foreach ($newVersionAttributes as $attribute) { $versionDataMap[$attribute->contentClassAttributeIdentifier()] = $attribute; } // Start updating new version $version->setAttribute('modified', time()); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $db = eZDB::instance(); $db->begin(); $version->store(); foreach ($publishedDataMap as $attr => $value) { $versionDataMap[$attr]->setAttribute('data_text', $value->attribute('data_text')); $versionDataMap[$attr]->store(); } $db->commit(); return $version; }
/** * Forza l'importazione di una playlist alla prossima esecuzione * del cronjob. * * Ritorna true se la playlist è stata rischedulata * * @param int $parentNodeID * @return boolean */ public static function forcePlaylistImport($parentNodeID) { $limit = 1000; $offset = 0; $imports = SQLIScheduledImport::fetchList($offset, $limit); foreach ($imports as $import) { if ($import instanceof SQLIScheduledImport) { $options = $import->getOptions(); if ($options->hasAttribute('parentnodeid')) { $_parentNodeID = $options->attribute('parentnodeid'); if ($parentNodeID == $_parentNodeID) { $db = eZDB::instance(); $db->begin(); // Imposta il giorno precedente rispetto al timestamp attuale $currentNextTime = $import->attribute('next'); $nextTimeInterval = '-1 day'; $nextTime = strtotime($nextTimeInterval, $currentNextTime); $import->setAttribute('next', $nextTime); $import->store(array('next')); $db->commit(); return true; } } } else { throw new Exception('Classe errata!'); } } //echo("!"); //die(); return false; }
function applyChanges($module, $http, $vatTypeArray = false) { $errors = array(); if ($vatTypeArray === false) { $vatTypeArray = eZVatType::fetchList(true, true); } $db = eZDB::instance(); $db->begin(); foreach ($vatTypeArray as $vatType) { $id = $vatType->attribute('id'); if ($id == -1) { // avoid storing changes to the "fake" dynamic VAT type continue; } if ($http->hasPostVariable("vattype_name_" . $id)) { $name = $http->postVariable("vattype_name_" . $id); } if ($http->hasPostVariable("vattype_percentage_" . $id)) { $percentage = $http->postVariable("vattype_percentage_" . $id); } if (!$name || $percentage < 0 || $percentage > 100) { if (!$name) { $errors[] = ezpI18n::tr('kernel/shop/vattype', 'Empty VAT type names are not allowed (corrected).'); } else { $errors[] = ezpI18n::tr('kernel/shop/vattype', 'Wrong VAT percentage (corrected).'); } continue; } $vatType->setAttribute('name', $name); $vatType->setAttribute('percentage', $percentage); $vatType->store(); } $db->commit(); return $errors; }
/** * This method validates unique URL. * * @param string $data * @param object $contentObjectAttribute * @return boolean */ public static function validateUniqueURLHTTPInput($data, $contentObjectAttribute) { $ini = eZINI::instance('uniquedatatypes.ini'); $uniqueURLINI = $ini->group('UniqueURLSettings'); if (count($uniqueURLINI['AllowedSchemaList'])) { if (!eregi("^(" . implode('|', $uniqueURLINI['AllowedSchemaList']) . ")", $data)) { $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/ezuniquedatatypes', 'Only URLs beginning with "%schemas" are accepted!', '', array('%schemas' => implode('", "', $uniqueURLINI['AllowedSchemaList'])))); return eZInputValidator::STATE_INVALID; } } $url = eZURL::urlByURL($data); if (is_object($url)) { $contentObjectID = $contentObjectAttribute->ContentObjectID; $contentClassAttributeID = $contentObjectAttribute->ContentClassAttributeID; $db = eZDB::instance(); if ($uniqueURLINI['CurrentVersionOnly'] == 'true') { $query = "SELECT COUNT(*) AS row_counter\n\t\t\t\t\tFROM ezcontentobject co, ezcontentobject_attribute coa\n\t\t\t\t\tWHERE co.id = coa.contentobject_id\n\t\t\t\t\tAND co.current_version = coa.version\n\t\t\t\t\tAND coa.contentclassattribute_id = " . $db->escapeString($contentClassAttributeID) . "\n\t\t\t\t\tAND coa.contentobject_id <> " . $db->escapeString($contentObjectID) . "\n AND coa.data_int = " . $db->escapeString($url->ID); } else { $query = "SELECT COUNT(*) AS row_counter\n\t\t\t\t\tFROM ezcontentobject_attribute coa\n\t\t\t\t\tWHERE coa.contentclassattribute_id = " . $db->escapeString($contentClassAttributeID) . "\n\t\t\t\t\tAND coa.contentobject_id <> " . $db->escapeString($contentObjectID) . "\n AND coa.data_int = " . $db->escapeString($url->ID); } if (self::EZUNIQUEURL_DEBUG) { eZDebug::writeDebug('Query: ' . $query, 'eZUniqueURLType::validateUniqueURLHTTPInput'); } $rows = $db->arrayQuery($query); $rowCount = (int) $rows[0]['row_counter']; if ($rowCount >= 1) { $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/ezuniquedatatypes', 'Given URL already exists in another content object of this type!')); return eZInputValidator::STATE_INVALID; } } return eZInputValidator::STATE_ACCEPTED; }
function applyChanges( $module, $http, $productCategories = false ) { $errors = array(); if ( $productCategories === false ) $productCategories = eZProductCategory::fetchList(); $db = eZDB::instance(); $db->begin(); foreach ( $productCategories as $cat ) { $id = $cat->attribute( 'id' ); if ( !$http->hasPostVariable( "category_name_" . $id ) ) continue; $name = $http->postVariable( "category_name_" . $id ); if ( !$name ) { $errors[] = ezpI18n::tr( 'kernel/shop/productcategories', 'Empty category names are not allowed (corrected).' ); continue; } $cat->setAttribute( 'name', $name ); $cat->store(); } $db->commit(); return $errors; }
/** * Test that saving a content class in DEFINED version status * correctly manipulate associated class groups * * @link http://issues.ez.no/16197 */ public function testContentClassStillInGroupAfterEdition() { $class = eZContentClass::fetch( $this->class->id ); // This is logic contained in kernel/class/edit.php foreach ( eZContentClassClassGroup::fetchGroupList( $class->attribute( 'id' ), eZContentClass::VERSION_STATUS_DEFINED ) as $classGroup ) { eZContentClassClassGroup::create( $class->attribute( 'id' ), eZContentClass::VERSION_STATUS_TEMPORARY, $classGroup->attribute( 'group_id' ), $classGroup->attribute( 'group_name' ) ) ->store(); } $attributes = $class->fetchAttributes(); $class->setAttribute( 'version', eZContentClass::VERSION_STATUS_TEMPORARY ); $class->NameList->setHasDirtyData(); foreach ( $attributes as $attribute ) { $attribute->setAttribute( 'version', eZContentClass::VERSION_STATUS_TEMPORARY ); if ( $dataType = $attribute->dataType() ) $dataType->initializeClassAttribute( $attribute ); } $class->store( $attributes ); $db = eZDB::instance(); $db->begin(); $class->storeVersioned( $attributes, eZContentClass::VERSION_STATUS_DEFINED ); $db->commit(); $this->assertTrue( eZContentClassClassGroup::classInGroup( $class->attribute( 'id' ), eZContentClass::VERSION_STATUS_DEFINED, 1 ) ); }
/** * Create a copy of an object. * * The basis for this method is taken from kernel/content/copy.php * * @todo Merge this method into kernel wrapper's object class. * * @param eZContentObject $object * @param int $newParentNodeID * @return eZContentObject */ public static function copyObject($object, $newParentNodeID) { $newParentNode = eZContentObjectTreeNode::fetch($newParentNodeID); $db = eZDB::instance(); $db->begin(); $newObject = $object->copy(true); // We should reset section that will be updated in updateSectionID(). // If sectionID is 0 than the object has been newly created $newObject->setAttribute('section_id', 0); $newObject->store(); $curVersion = $newObject->attribute('current_version'); $curVersionObject = $newObject->attribute('current'); $newObjAssignments = $curVersionObject->attribute('node_assignments'); unset($curVersionObject); // remove old node assignments foreach ($newObjAssignments as $assignment) { $assignment->purge(); } // and create a new one $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $newObject->attribute('id'), 'contentobject_version' => $curVersion, 'parent_node' => $newParentNodeID, 'is_main' => 1)); $nodeAssignment->store(); // publish the newly created object eZOperationHandler::execute('content', 'publish', array('object_id' => $newObject->attribute('id'), 'version' => $curVersion)); // Update "is_invisible" attribute for the newly created node. $newNode = $newObject->attribute('main_node'); eZContentObjectTreeNode::updateNodeVisibility($newNode, $newParentNode); $db->commit(); return $newObject; }
protected static function initialize() { $db = eZDB::instance(); if ($db->databaseName() == 'mysql') { self::$view_groups['databaseqa']['disabled'] = false; } }
static function removeGroup( $workflowID, $workflowVersion, $selectedGroup ) { $workflow = eZWorkflow::fetch( $workflowID ); if ( !$workflow ) return false; $groups = $workflow->attribute( 'ingroup_list' ); foreach ( array_keys( $groups ) as $key ) { if ( in_array( $groups[$key]->attribute( 'group_id' ), $selectedGroup ) ) { unset( $groups[$key] ); } } if ( count( $groups ) == 0 ) { return false; } else { $db = eZDB::instance(); $db->begin(); foreach( $selectedGroup as $group_id ) { eZWorkflowGroupLink::removeByID( $workflowID, $workflowVersion, $group_id ); } $db->commit(); } return true; }
private function ezflow_list_blocktypes($output) { $validOutput = array('simple', 'grouped'); if (!in_array($output, $validOutput)) { $output = 'simple'; } $db = eZDB::instance(); $sql['simple'] = "SELECT block_type, id as block_id FROM `ezm_block` ORDER BY `block_type` ASC"; $sql['grouped'] = "\n SELECT \n block_type, \n COUNT(block_type) as count, \n (SELECT \n GROUP_CONCAT(id) \n FROM \n `ezm_block` t2 \n WHERE \n t1.block_type = t2.block_type\n ) as block_ids \n FROM \n `ezm_block` t1 \n GROUP BY t1.block_type \n ORDER BY t1.`block_type` ASC;"; // header field names for each output mode $headers['simple'] = array("block_type", "block_id"); $headers['grouped'] = array("block_type", "count", "block_ids"); if ($query = $db->query($sql[$output])) { // add field headers row $results[] = $headers[$output]; while ($row = $query->fetch_array(MYSQL_NUM)) { $result = array(); foreach ($row as $index => $value) { $result[] = $value; } $results[] = $result; } eep::printTable($results, "ezflow list blocktypes [{$output}]"); } }
static function gather() { $contentTypes = array('Objects (including users)' => array('table' => 'ezcontentobject'), 'Users' => array('table' => 'ezuser'), 'Nodes' => array('table' => 'ezcontentobject_tree'), 'Content Classes' => array('table' => 'ezcontentclass'), 'Information Collections' => array('table' => 'ezinfocollection'), 'Pending notification events' => array('table' => 'eznotificationevent', 'wherecondition' => 'status = 0'), 'Objects pending indexation' => array('table' => 'ezpending_actions', 'wherecondition' => "action = 'index_object'"), 'Binary files (content)' => array('table' => 'ezbinaryfile'), 'Image files (content)' => array('table' => 'ezimagefile'), 'Media files (content)' => array('table' => 'ezmedia'), 'Maximum children per node' => array('sql' => 'SELECT MAX(tot) AS NUM FROM ( SELECT count(*) AS tot FROM ezcontentobject_tree GROUP BY parent_node_id ) nodes'), 'Maximum nodes per object' => array('sql' => 'SELECT MAX(tot) AS NUM FROM ( SELECT count(*) AS tot FROM ezcontentobject_tree GROUP BY contentobject_id ) nodes'), 'Maximum incoming relations to an object' => array('sql' => 'SELECT MAX(tot) AS NUM FROM ( SELECT count(*) AS tot FROM ezcontentobject_link GROUP BY to_contentobject_id ) links', 'nvl' => 0), 'Maximum outgoing relations from an object' => array('sql' => 'SELECT MAX(tot) AS NUM FROM ( SELECT count(*) AS tot FROM ezcontentobject_link GROUP BY from_contentobject_id ) links', 'nvl' => 0)); $db = eZDB::instance(); $contentList = array(); foreach ($contentTypes as $key => $desc) { if (isset($desc['table'])) { $sql = 'SELECT COUNT(*) AS NUM FROM ' . $desc['table']; if (@$desc['wherecondition']) { $sql .= ' WHERE ' . $desc['wherecondition']; } } else { $sql = $desc['sql']; } $count = $db->arrayQuery($sql); $contentList[$key] = $count[0]['NUM'] === null ? $desc['nvl'] : $count[0]['NUM']; } if (in_array('ezfind', eZExtension::activeExtensions())) { $ini = eZINI::instance('solr.ini'); $ezfindpingurl = $ini->variable('SolrBase', 'SearchServerURI') . "/admin/stats.jsp"; $data = eZHTTPTool::getDataByURL($ezfindpingurl, false); //var_dump( $data ); if (preg_match('#<stat +name="numDocs" ?>([^<]+)</stat>#', $data, $matches)) { $contentList['Documents in SOLR'] = trim($matches[1]); } else { $contentList['Documents in SOLR'] = 'Unknown'; } } return $contentList; }
function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters) { $parentNodeID = $namedParameters['parent_node_id']; switch ($operatorName) { case 'ezkeywordlist': include_once 'lib/ezdb/classes/ezdb.php'; $db = eZDB::instance(); if ($parentNodeID) { $node = eZContentObjectTreeNode::fetch($parentNodeID); if ($node) { $pathString = "AND ezcontentobject_tree.path_string like '" . $node->attribute('path_string') . "%'"; } $parentNodeIDSQL = "AND ezcontentobject_tree.node_id != " . (int) $parentNodeID; } $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(true, false); $limitation = false; $limitationList = eZContentObjectTreeNode::getLimitationList($limitation); $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList); $versionNameJoins = " AND ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id AND\n ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version AND "; $languageFilter = " AND " . eZContentLanguage::languagesSQLFilter('ezcontentobject'); $versionNameJoins .= eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject'); $quotedClassIdentifiers = array(); foreach ((array) $namedParameters['class_identifier'] as $classIdentifier) { $quotedClassIdentifiers[] = "'" . $db->escapeString($classIdentifier) . "'"; } $rs = $db->arrayQuery("SELECT DISTINCT ezkeyword.keyword\n FROM ezkeyword_attribute_link,\n ezkeyword,\n ezcontentobject,\n ezcontentobject_name,\n ezcontentobject_attribute,\n ezcontentobject_tree,\n ezcontentclass\n {$sqlPermissionChecking['from']}\n WHERE ezkeyword.id = ezkeyword_attribute_link.keyword_id\n AND ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id\n AND ezcontentobject_tree.contentobject_id = ezcontentobject_attribute.contentobject_id\n AND ezkeyword.class_id = ezcontentclass.id\n AND " . $db->generateSQLINStatement($quotedClassIdentifiers, 'ezcontentclass.identifier') . "\n {$pathString}\n {$parentNodeIDSQL} " . ($namedParameters['depth'] > 0 ? "AND ezcontentobject_tree.depth=" . (int) $namedParameters['depth'] : '') . "\n {$showInvisibleNodesCond}\n {$sqlPermissionChecking['where']}\n {$languageFilter}\n {$versionNameJoins}\n ORDER BY ezkeyword.keyword ASC"); $operatorValue = $rs; break; } }
function fetchSearchListCount() { $db = eZDB::instance(); $query = "SELECT count(*) as count FROM ezsearch_search_phrase"; $searchListCount = $db->arrayQuery($query); return array('result' => $searchListCount[0]['count']); }
static function cleanup($db) { if ($db === null) { $db = eZDB::instance(); } $relationTypes = $db->supportedRelationTypes(); $result = true; $defaultRegexp = "#^ez|tmp_notification_rule_s#"; foreach ($relationTypes as $relationType) { $relationItems = $db->relationList($relationType); // This is the default regexp, unless the db driver provides one $matchRegexp = null; if (method_exists($db, 'relationMatchRegexp')) { $matchRegexp = $db->relationMatchRegexp($relationType); } if ($matchRegexp === null) { $matchRegexp = $defaultRegexp; } foreach ($relationItems as $relationItem) { // skip relations that shouldn't be touched if ($matchRegexp !== false and !preg_match($matchRegexp, $relationItem)) { continue; } if (!$db->removeRelation($relationItem, $relationType)) { $result = false; break; } } if (!$result) { break; } } return $result; }
/** * Executes checks for db configuration errors that are not exposed by the * default db upgrade check test */ static function checkDatabase() { $db = eZDB::instance(); $type = $db->databaseName(); switch ($type) { case 'mysql': $ini = eZINI::instance(); $dbname = $ini->variable('DatabaseSettings', 'Database'); $warnings = array(); foreach ($db->arrayquery("SELECT table_name, table_collation, engine FROM information_schema.tables WHERE table_schema = '" . $db->escapeString($dbname) . "'") as $row) { if ($row['engine'] != 'InnoDB') { $warnings[] = "Table " . $row['table_name'] . " does not use the InnoDB storage engine: " . $row['engine']; } if (substr($row['table_collation'], 0, 5) != 'utf8_') { $warnings[] = "Table " . $row['table_name'] . " does not use an utf8 character set: " . $row['table_collation']; } } return $warnings; //case 'oracle': /// @todo check for stored procs which are not compiled; tables with max id bigger than their associated sequence; double triggers on tables //case 'oracle': /// @todo check for stored procs which are not compiled; tables with max id bigger than their associated sequence; double triggers on tables default: return array('Database type ' . $db->databaseName() . ' can currently not be checked for problems'); } }
function fetchClassListByGroups( $groupFilter, $groupFilterType = 'include' ) { $notIn = ( $groupFilterType == 'exclude' ); if ( is_array( $groupFilter ) && count( $groupFilter ) > 0 ) { $db = eZDB::instance(); $groupFilter = $db->generateSQLINStatement( $groupFilter, 'ccg.group_id', $notIn ); $classNameFilter = eZContentClassName::sqlFilter( 'cc' ); $version = eZContentClass::VERSION_STATUS_DEFINED; $sql = "SELECT DISTINCT cc.*, $classNameFilter[nameField] " . "FROM ezcontentclass cc, ezcontentclass_classgroup ccg, $classNameFilter[from] " . "WHERE cc.version = $version" . " AND cc.id = ccg.contentclass_id" . " AND $groupFilter" . " AND $classNameFilter[where] " . "ORDER BY $classNameFilter[nameField] ASC"; $rows = $db->arrayQuery( $sql ); $classes = eZPersistentObject::handleRows( $rows, 'eZContentClass', true ); } else { $classes = eZContentClass::fetchList( eZContentClass::VERSION_STATUS_DEFINED, true, false, array( 'name' => 'asc' ) ); } return array( 'result' => $classes ); }
/** * Creates and returns SQL parts used in fetch functions * * @return array */ function createSqlParts($params) { $returnArray = array('tables' => '', 'joins' => '', 'columns' => ''); if (isset($params['tag_id'])) { if (is_array($params['tag_id'])) { $tagIDsArray = $params['tag_id']; } else { if ((int) $params['tag_id'] > 0) { $tagIDsArray = array((int) $params['tag_id']); } else { return $returnArray; } } if (!isset($params['include_synonyms']) || isset($params['include_synonyms']) && (bool) $params['include_synonyms'] == true) { $result = eZTagsObject::fetchList(array('main_tag_id' => array($tagIDsArray)), null, false); if (is_array($result) && !empty($result)) { foreach ($result as $r) { array_push($tagIDsArray, (int) $r['id']); } } } $returnArray['tables'] = " INNER JOIN eztags_attribute_link i1 ON (i1.object_id = ezcontentobject.id AND i1.objectattribute_version = ezcontentobject.current_version)"; $db = eZDB::instance(); $dbString = $db->generateSQLINStatement($tagIDsArray, 'i1.keyword_id', false, true, 'int'); $returnArray['joins'] = " {$dbString} AND "; } return $returnArray; }
/** * Test that fetching the language listing, works after languages * have been altered in database, and then later refetched. * * @link http://issues.ez.no/15484 */ public function testMapLanguage() { $db = eZDB::instance(); eZContentLanguage::addLanguage('nno-NO', 'Nynorsk'); $localeToChangeInto = 'dan-DK'; $languageNameToChangeInto = 'Danish'; $langObject = eZContentLanguage::fetchByLocale('nno-NO'); $langId = (int) $langObject->attribute('id'); $updateSql = <<<END UPDATE ezcontent_language SET locale='{$localeToChangeInto}', name='{$languageNameToChangeInto}' WHERE id={$langId} END; $db->query($updateSql); eZContentLanguage::expireCache(); $newLangObject = eZContentLanguage::fetchByLocale($localeToChangeInto); if (!$newLangObject instanceof eZContentLanguage) { self::fail("Language object not returned. Old version provided by cache?"); } $newLangId = (int) $newLangObject->attribute('id'); self::assertEquals($langId, $newLangId, "New language not mapped to existing language"); }
function eZDBCleanup() { if (class_exists('ezdb') and eZDB::hasInstance()) { $db = eZDB::instance(); $db->setIsSQLOutputEnabled(false); } }
/** * Helper function that creates 3 tables, two of them having foreign keys towards the first one */ public function createFKTables() { $db = eZDB::instance(); $db->query( "CREATE TABLE eztestfk_1 ( id1 INT NOT NULL, id2 INT NOT NULL, id3 INT NOT NULL, PRIMARY KEY (id1), INDEX eztestfk_1_1 (id1), INDEX eztestfk_1_2 (id2, id3) ) ENGINE=InnoDB" ); $db->query( "CREATE TABLE eztestfk_2 ( id INT NOT NULL, fk1 INT NULL, fk2 INT NULL, fk3 INT NULL, PRIMARY KEY (id) , CONSTRAINT eztestfk_2_fk1 FOREIGN KEY ( fk1 ) REFERENCES eztestfk_1 (id1) ON DELETE CASCADE, CONSTRAINT eztestfk_2_fk2 FOREIGN KEY ( fk2, fk3 ) REFERENCES eztestfk_1 (id2, id3) ON DELETE CASCADE ) ENGINE=InnoDB" ); $db->query( "CREATE TABLE eztestfk_3 ( id INT NOT NULL, fk1 INT NULL, PRIMARY KEY (id) , CONSTRAINT eztestfk_3_fk1 FOREIGN KEY ( fk1 ) REFERENCES eztestfk_1 (id1) ON DELETE CASCADE ) ENGINE=InnoDB" ); }
/** * Tests that the output process works with objects. * * There should be no crash from casting errors. * @group templateOperators * @group attributeOperator */ public function testDisplayVariableWithObject() { $db = eZDB::instance(); // STEP 1: Add test folder $folder = new ezpObject( "folder", 2 ); $folder->name = __METHOD__; $folder->publish(); $nodeId = $folder->mainNode->node_id; $node = eZContentObjectTreeNode::fetch( $nodeId ); $attrOp = new eZTemplateAttributeOperator(); $outputTxt = ''; $formatterMock = $this->getMock( 'ezpAttributeOperatorFormatterInterface' ); $formatterMock->expects( $this->any() ) ->method( 'line' ) ->will( $this->returnValue( __METHOD__ ) ); try { $attrOp->displayVariable( $node, $formatterMock, true, 2, 0, $outputTxt ); } catch ( PHPUnit_Framework_Error $e ) { self::fail( "eZTemplateAttributeOperator raises an error when working with objects." ); } self::assertNotNull( $outputTxt, "Output text is empty." ); // this is an approxmiate test. The output shoudl contain the name of the object it has been generated correctly. self::assertContains( __METHOD__, $outputTxt, "There is something wrong with the output of the attribute operator. Object name not found." ); }
function install($package, $installType, $parameters, $name, $os, $filename, $subdirectory, $content, &$installParameters, &$installData) { $path = $package->path(); $databaseType = false; if (isset($parameters['database-type'])) { $databaseType = $parameters['database-type']; } $path .= '/' . eZDBPackageHandler::sqlDirectory(); if ($databaseType) { $path .= '/' . $databaseType; } if (file_exists($path)) { $db = eZDB::instance(); $canInsert = true; if ($databaseType and $databaseType != $db->databaseName()) { $canInsert = false; } if ($canInsert) { eZDebug::writeDebug("Installing SQL file {$path}/{$filename}"); $db->insertFile($path, $filename, false); return true; } else { eZDebug::writeDebug("Skipping SQL file {$path}/{$filename}"); } } else { eZDebug::writeError("Could not find SQL file {$path}/{$filename}"); } return false; }
/** * Returns a shared instance of the eZDBSchemaInterface class. * * @param array|eZDBInterface|false $params If array, following key is needed: * - instance: the eZDB instance (optional), if none provided, eZDB::instance() will be used. * @return eZDBSchemaInterface|false */ static function instance($params = false) { if (is_object($params)) { $db = $params; $params = array('instance' => $db); } if (!isset($params['instance'])) { $db = eZDB::instance(); $params['instance'] = $db; } $db = $params['instance']; if (!isset($params['type'])) { $params['type'] = $db->databaseName(); } if (!isset($params['schema'])) { $params['schema'] = false; } $dbname = $params['type']; /* Load the database schema handler INI stuff */ $ini = eZINI::instance('dbschema.ini'); $schemaPaths = $ini->variable('SchemaSettings', 'SchemaPaths'); $schemaHandlerClasses = $ini->variable('SchemaSettings', 'SchemaHandlerClasses'); /* Check if we have a handler */ if (!isset($schemaPaths[$dbname]) or !isset($schemaHandlerClasses[$dbname])) { eZDebug::writeError("No schema handler for database type: {$dbname}", __METHOD__); return false; } /* Include the schema file and instantiate it */ require_once $schemaPaths[$dbname]; return new $schemaHandlerClasses[$dbname]($params); }
/** * Test case teardown * Restores the INI settings changed in setUp */ public function tearDown() { eZDB::instance()->query('DELETE FROM ezurlwildcard'); eZURLWildcard::expireCache(); clearstatcache(); sleep(1); parent::tearDown(); }
/** * Inserts one or more sql files into the test database * * @param eZDB $db * @param array $sqlFiles array( array( string => string ) ) * @return bool */ public static function insertSqlData($db, $sqlFiles) { if (!is_array($sqlFiles) or count($sqlFiles) <= 0) { return false; } foreach ($sqlFiles as $sqlFile) { if (is_array($sqlFile)) { $success = $db->insertFile($sqlFile[0], $sqlFile[1]); } else { $success = $db->insertFile(dirname($sqlFile), basename($sqlFile), false); } if (!$success) { return false; } } return true; }
/** * Removes a wildcard based on a source_url. * The URL should be provided without the /* prefix: * foobar will remove the wildcard with source_url = foobar/* * @param string $baseURL URL prefix matched against destination_url * @return void */ static function cleanup($baseURL) { $db = eZDB::instance(); $baseURLText = $db->escapeString($baseURL . "/*"); $sql = "DELETE FROM ezurlwildcard\n WHERE source_url = '{$baseURLText}'"; $db->query($sql); self::expireCache(); }
static function cleanAll() { $db = eZDB::instance(); $definition = eZISBNGroup::definition(); $table = $definition['name']; $sql = "TRUNCATE TABLE " . $table; $db->query($sql); }
protected function tearDown() { if (ezpTestRunner::dbPerTest()) { $db = eZDB::instance(); $db->close(); } parent::tearDown(); }
static function removeClassName($contentClassID, $contentClassVersion) { $db = eZDB::instance(); $db->begin(); $sql = "DELETE FROM ezcontentclass_name WHERE contentclass_id = {$contentClassID} AND contentclass_version = {$contentClassVersion}"; $db->query($sql); $db->commit(); }
static function move($nodeID, $newParentNodeID) { $result = false; if (!is_numeric($nodeID) || !is_numeric($newParentNodeID)) { return false; } $node = eZContentObjectTreeNode::fetch($nodeID); if (!$node) { return false; } $object = $node->object(); if (!$object) { return false; } $objectID = $object->attribute('id'); $oldParentNode = $node->fetchParent(); $oldParentObject = $oldParentNode->object(); // clear user policy cache if this is a user object if (in_array($object->attribute('contentclass_id'), eZUser::contentClassIDs())) { eZUser::purgeUserCacheByUserId($object->attribute('id')); } // clear cache for old placement. eZContentCacheManager::clearContentCacheIfNeeded($objectID); $db = eZDB::instance(); $db->begin(); $node->move($newParentNodeID); $newNode = eZContentObjectTreeNode::fetchNode($objectID, $newParentNodeID); if ($newNode) { $newNode->updateSubTreePath(true, true); if ($newNode->attribute('main_node_id') == $newNode->attribute('node_id')) { // If the main node is moved we need to check if the section ID must change $newParentNode = $newNode->fetchParent(); $newParentObject = $newParentNode->object(); if ($object->attribute('section_id') != $newParentObject->attribute('section_id')) { eZContentObjectTreeNode::assignSectionToSubTree($newNode->attribute('main_node_id'), $newParentObject->attribute('section_id'), $oldParentObject->attribute('section_id')); } } // modify assignment $curVersion = $object->attribute('current_version'); $nodeAssignment = eZNodeAssignment::fetch($objectID, $curVersion, $oldParentNode->attribute('node_id')); if ($nodeAssignment) { $nodeAssignment->setAttribute('parent_node', $newParentNodeID); $nodeAssignment->setAttribute('op_code', eZNodeAssignment::OP_CODE_MOVE); $nodeAssignment->store(); // update search index $nodeIDList = array($nodeID); eZSearch::removeNodeAssignment($node->attribute('main_node_id'), $newNode->attribute('main_node_id'), $object->attribute('id'), $nodeIDList); eZSearch::addNodeAssignment($newNode->attribute('main_node_id'), $object->attribute('id'), $nodeIDList); } $result = true; } else { eZDebug::writeError("Node {$nodeID} was moved to {$newParentNodeID} but fetching the new node failed"); } $db->commit(); // clear cache for new placement. eZContentCacheManager::clearContentCacheIfNeeded($objectID); return $result; }