예제 #1
0
 /**
  * Initialize ezpClass object
  *
  * @param string $name
  * @param string $identifier
  * @param string $contentObjectName
  * @param int $creatorID
  * @param string $language
  * @param int $groupID
  * @param string $groupName
  */
 public function __construct($name = 'Test class', $identifier = 'test_class', $contentObjectName = '<test_attribute>', $creatorID = 14, $language = 'eng-GB', $groupID = 1, $groupName = 'Content')
 {
     if (eZContentLanguage::fetchByLocale($language) === false) {
         $topPriorityLanguage = eZContentLanguage::topPriorityLanguage();
         if ($topPriorityLanguage) {
             $language = $topPriorityLanguage->attribute('locale');
         }
     }
     $this->language = $language;
     $this->class = eZContentClass::create($creatorID, array(), $this->language);
     $this->class->setName($name, $this->language);
     $this->class->setAttribute('contentobject_name', $contentObjectName);
     $this->class->setAttribute('identifier', $identifier);
     $this->class->store();
     $languageID = eZContentLanguage::idByLocale($this->language);
     $this->class->setAlwaysAvailableLanguageID($languageID);
     $this->classGroup = eZContentClassClassGroup::create($this->id, $this->version, $groupID, $groupName);
     $this->classGroup->store();
 }
예제 #2
0
 public static function checkContentRequirements($module, $http)
 {
     // Check that the object params are 'ok'
     if (!$http->hasPostVariable('ContentObjectID')) {
         eZDebug::writeError('No content object id is provided', 'ezcomments');
         return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
     }
     $contentObjectId = (int) $http->postVariable('ContentObjectID');
     // Either use provided language code, or fallback on siteaccess default
     if ($http->hasPostVariable('CommentLanguageCode')) {
         $languageCode = $http->postVariable('CommentLanguageCode');
         $language = eZContentLanguage::fetchByLocale($languageCode);
         if ($language === false) {
             eZDebug::writeError("The language code [{$languageCode}] given is not valid in the system.", 'ezcomments');
             return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
         }
     } else {
         $defaultLanguage = eZContentLanguage::topPriorityLanguage();
         $languageCode = $defaultLanguage->attribute('locale');
     }
     // Check that our object is actually a valid holder of comments
     $contentObject = eZContentObject::fetch($contentObjectId);
     if (!$contentObject instanceof eZContentObject) {
         eZDebug::writeError('No content object exists for the given id.', 'ezcomments');
         return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
     }
     $dataMap = $contentObject->fetchDataMap(false, $languageCode);
     $foundCommentAttribute = false;
     foreach ($dataMap as $attr) {
         if ($attr->attribute('data_type_string') === 'ezcomcomments') {
             $foundCommentAttribute = $attr;
             break;
         }
     }
     // if there is no ezcomcomments attribute inside the content, return
     if (!$foundCommentAttribute) {
         eZDebug::writeError("Content object with id [{$contentObjectId}], does not contain an ezcomments attribute.", 'ezcomments');
         return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
     }
     return compact('contentObjectId', 'languageCode', 'contentObject', 'foundCommentAttribute');
 }
 static function storePath($path, $action, $languageName = false, $linkID = false, $alwaysAvailable = false, $rootID = false, $cleanupElements = true, $autoAdjustName = false, $reportErrors = true, $aliasRedirects = true)
 {
     $path = eZURLAliasML::cleanURL($path);
     if ($languageName === false) {
         $languageName = eZContentLanguage::topPriorityLanguage();
     }
     if (is_object($languageName)) {
         $languageObj = $languageName;
         $languageID = (int) $languageName->attribute('id');
         $languageName = $languageName->attribute('locale');
     } else {
         $languageObj = eZContentLanguage::fetchByLocale($languageName);
         $languageID = (int) $languageObj->attribute('id');
     }
     $languageMask = $languageID;
     if ($alwaysAvailable) {
         $languageMask |= 1;
     }
     $path = eZURLAliasML::cleanURL($path);
     $elements = explode('/', $path);
     $db = eZDB::instance();
     $parentID = 0;
     // If the root ID is specified we will start the parent search from that
     if ($rootID !== false) {
         $parentID = $rootID;
     }
     $i = 0;
     // Top element is handled separately.
     $topElement = array_pop($elements);
     // Find correct parent, and create missing ones if necessary
     $createdPath = array();
     foreach ($elements as $element) {
         $actionStr = $db->escapeString($action);
         if ($cleanupElements) {
             $element = eZURLAliasML::convertToAlias($element, 'noname' . (count($createdPath) + 1));
         }
         $elementStr = $db->escapeString(eZURLAliasML::strtolower($element));
         $query = "SELECT * FROM ezurlalias_ml WHERE text_md5 = " . eZURLAliasML::md5($db, $elementStr, false) . " AND parent = {$parentID}";
         $rows = $db->arrayQuery($query);
         if (count($rows) == 0) {
             // Create a fake element to ensure we have a parent
             $elementObj = eZURLAliasML::create($element, "nop:", $parentID, 1);
             $elementObj->store();
             $parentID = (int) $elementObj->attribute('id');
         } else {
             $parentID = (int) $rows[0]['link'];
         }
         $createdPath[] = $element;
         ++$i;
     }
     if ($parentID != 0) {
         $sql = "SELECT text, parent FROM ezurlalias_ml WHERE id = {$parentID}";
         $rows = $db->arrayQuery($sql);
         if (count($rows) > 0) {
             // A special case. If the special entry with empty text is used as parent
             // the parent must be adjust to 0 (ie. real top level).
             if (strlen($rows[0]['text']) == 0 && $rows[0]['parent'] == 0) {
                 $createdPath = array();
                 $parentID = 0;
             }
         }
     }
     if (!preg_match("#^(.+):(.+)\$#", $action, $matches)) {
         return array('status' => self::ACTION_INVALID, 'error_message' => "The action value " . var_export($action, true) . " is invalid", 'error_number' => self::ACTION_INVALID, 'path' => null, 'element' => null);
     }
     $actionName = $matches[1];
     $actionValue = $matches[2];
     $existingElementID = null;
     $alwaysMask = $alwaysAvailable ? 1 : 0;
     $actionStr = $db->escapeString($action);
     $actionTypeStr = $db->escapeString($actionName);
     $createdElement = null;
     if ($linkID === false) {
         if ($cleanupElements) {
             $topElement = eZURLAliasML::convertToAlias($topElement, 'noname' . (count($createdPath) + 1));
         }
         $adjustName = false;
         $curElementID = null;
         $newElementID = null;
         $newText = $topElement;
         $uniqueCounter = 0;
         // Loop until we a valid entry point, which means:
         // 1. The entry does not exist yet, so create a new one
         // 2. The entry exists but is re-usable (e.g. nop or same action)
         // 3. The entry exists and cannot be re-used, instead the name is adjusted to be unique.
         while (true) {
             $newText = $topElement;
             if ($uniqueCounter > 0) {
                 $newText .= $uniqueCounter + 1;
             }
             $textMD5 = eZURLAliasML::md5($db, $newText);
             $query = "SELECT * FROM ezurlalias_ml WHERE parent = {$parentID} AND text_md5 = {$textMD5}";
             $rows = $db->arrayQuery($query);
             if (count($rows) == 0) {
                 // No such entry, create a new one
                 break;
             }
             $row = $rows[0];
             $curID = (int) $row['id'];
             $curAction = $row['action'];
             if ($curAction == 'nop:' || $curAction == $action || $row['is_original'] == 0) {
                 // We can reuse the element so record the ID
                 $curElementID = $curID;
                 $newElementID = $curID;
                 break;
             }
             if (!$autoAdjustName) {
                 if ($reportErrors) {
                     eZDebug::writeError("Tried to store path '{$path}' but the path already exists (ID: {$curID}) but with action '{$curAction}', the new action was '{$action}'");
                 }
                 return array('status' => self::LINK_ALREADY_TAKEN, 'path' => $path, 'element' => null);
             }
             // Need to adjust name, re-iterate
             ++$uniqueCounter;
         }
         $textEsc = $db->escapeString($newText);
         // See if there is already a node in the same level with the same action
         if ($newElementID === null) {
             $query = "SELECT * FROM ezurlalias_ml " . "WHERE parent = {$parentID} AND action = '{$actionStr}' AND is_original = 1 AND is_alias = 0";
             $rows = $db->arrayQuery($query);
             if (count($rows) > 0) {
                 $newElementID = (int) $rows[0]['id'];
             }
         }
         // Create or update the element
         if ($curElementID !== null) {
             // Check if an already existing entry at the same level exists, with a different id
             // if so the id must be updated.
             $query = "SELECT * FROM ezurlalias_ml " . "WHERE parent = {$parentID} AND action = '{$actionStr}' AND is_original = 1 AND is_alias = 0";
             $rows = $db->arrayQuery($query);
             if (count($rows) > 0) {
                 $existingEntryId = (int) $rows[0]['id'];
                 if ($existingEntryId != $curElementID) {
                     // move history entry to the same id
                     $query = "UPDATE ezurlalias_ml SET id = {$existingEntryId} " . "WHERE parent = {$parentID} AND text_md5 = {$textMD5}";
                     $res = $db->query($query);
                     if (!$res) {
                         return eZURLAliasML::dbError($db);
                     }
                     $curElementID = $existingEntryId;
                 }
             }
             $bitOr = $db->bitOr($db->bitAnd('lang_mask', ~1), $languageMask);
             // Note: The `text` field is updated too, this ensures case-changes are stored.
             $query = "UPDATE ezurlalias_ml SET link = id, lang_mask = {$bitOr}, text = '{$textEsc}', action = '{$actionStr}', action_type = '{$actionTypeStr}', is_alias = 0, is_original = 1 " . "WHERE parent = {$parentID} AND text_md5 = {$textMD5}";
             $res = $db->query($query);
             if (!$res) {
                 return eZURLAliasML::dbError($db);
             }
             $newElementID = $curElementID;
         } else {
             $element = new eZURLAliasML(array('id' => $newElementID, 'link' => null, 'parent' => $parentID, 'text' => $newText, 'lang_mask' => $languageID | $alwaysMask, 'action' => $action));
             $element->store();
             $newElementID = (int) $element->attribute('id');
             $createdElement = $element;
         }
         $createdPath[] = $newText;
         // OMS-urlalias-fix: We want to retain the lang_mask of url entries, but mark others as history elements is_original = 0
         // Furthermore this change is not performed on custom alias entries.
         $bitAnd = $db->bitAnd('lang_mask', $languageID);
         // First we look at the entries to mark as history entries, if an entry comprise more languages, it must not be set as history element.
         $query = "SELECT * FROM ezurlalias_ml " . "WHERE action = '{$actionStr}' AND ({$bitAnd} > 0) AND is_original = 1 AND is_alias = 0 AND (parent != {$parentID} OR text_md5 != {$textMD5})";
         $toBeUpdated = $db->arrayQuery($query);
         // 0. Check if the entry to be updated represents multiple languages:
         // IF YES:
         //  1. "Downgrade" existing entry, by removing the active translation's language id from the language_mask.
         // IF NO:
         //  1. Mark entry as a history entry
         if (count($toBeUpdated) > 0) {
             $languageMask = $toBeUpdated[0]['lang_mask'];
             if (($languageMask & ~($languageID | 1)) != 0) {
                 // "Composite entry", downgrade current entry
                 $currentEntry = new eZURLAliasML($toBeUpdated[0]);
                 $currentEntry->LangMask = (int) $currentEntry->LangMask & ~$languageID;
                 $currentEntry->store();
             } else {
                 // Mark as history element.
                 $query = "UPDATE ezurlalias_ml SET is_original = 0 " . "WHERE action = '{$actionStr}' AND ({$bitAnd} > 0) AND is_original = 1 AND is_alias = 0 AND (parent != {$parentID} OR text_md5 != {$textMD5})";
                 $res = $db->query($query);
                 if (!$res) {
                     return eZURLAliasML::dbError($db);
                 }
             }
         }
         // OMS-urlalias-fix: instead entries without language we look at history elements with same action (and language)
         // Look for other nodes with the same action and language
         // if found make then link to the new entry
         $bitAnd = $db->bitAnd('lang_mask', $languageID);
         $query = "SELECT * FROM ezurlalias_ml " . "WHERE action = '{$actionStr}' AND ({$bitAnd} > 0) AND is_original = 0 AND (parent != {$parentID} OR text_md5 != {$textMD5})";
         $rows = $db->arrayQuery($query);
         foreach ($rows as $row) {
             $idtmp = (int) $row['id'];
             if ($idtmp == $newElementID) {
                 $idtmp = self::getNewID();
             }
             $parentIDTmp = (int) $row['parent'];
             $textMD5Tmp = eZURLAliasML::md5($db, $row['text']);
             // OMS-urlalias-fix: We do not touch the lang_mask here
             $res = $db->query("UPDATE ezurlalias_ml SET id = {$idtmp}, link = {$newElementID}, is_alias = 0, is_original = 0 " . "WHERE parent = {$parentIDTmp} AND text_md5 = {$textMD5Tmp}");
             if (!$res) {
                 return eZURLAliasML::dbError($db);
             }
         }
         $res = $db->query($query);
         if (!$res) {
             return eZURLAliasML::dbError($db);
         }
         // Look for other nodes which is a link for the current action
         // if found make then link to the new entry
         // OMS-urlalias-fix: We only want to update the links of entries within the same language.
         // Also, only to be applied on normal entries, not custom aliases
         $bitAnd = $db->bitAnd('lang_mask', $languageID);
         $query = "UPDATE ezurlalias_ml SET link = {$newElementID}, is_alias = 0, is_original = 0 " . "WHERE action = '{$actionStr}' AND is_original = 0 AND is_alias = 0 AND ({$bitAnd} > 0) AND (parent != {$parentID} OR text_md5 != {$textMD5})";
         $res = $db->query($query);
         if (!$res) {
             return eZURLAliasML::dbError($db);
         }
         // Move children from old node to the new node
         // Conflicts:
         // New       |       Old |  Action
         // -------------------------------
         // Element   | Link      | Delete old
         // Element   | Element   | Will not happen, if so delete old
         // Element   | Other     | Reparent with new name
         // Element   | nop       | Delete old
         // Link      | Link      | Delete old
         // Link      | Element   | Delete new, reparent
         // Link      | Other     | Delete new, reparent
         // Link      | nop       | Delete old
         // nop       | Link      | Delete new, reparent
         // nop       | Element   | Delete new, reparent
         // nop       | nop       | Delete old
         // TODO: Handle all conflict cases, for now only the `Delete old, reparent` action is done
         // OMS-urlalias-fix: We are only updating child nodes within the same language,
         // and only for real system-generated url aliases. Custom aliases are left alone.
         $bitAnd = $db->bitAnd('lang_mask', $languageID);
         $query = "SELECT id FROM ezurlalias_ml " . "WHERE action = '{$actionStr}' AND is_alias = 0 AND (parent != {$parentID} OR text_md5 != {$textMD5})";
         $rows = $db->arrayQuery($query);
         foreach ($rows as $row) {
             $oldParentID = (int) $row['id'];
             $query = "UPDATE ezurlalias_ml SET parent = {$newElementID} " . "WHERE parent = {$oldParentID} AND ({$bitAnd} > 0)";
             $res = $db->query($query);
             if (!$res) {
                 return eZURLAliasML::dbError($db);
             }
         }
     } else {
         // Check the link ID
         if ($linkID !== true) {
             $linkID = (int) $linkID;
             // Step 1, find existing ID
             $query = "SELECT * FROM ezurlalias_ml WHERE id = '{$linkID}'";
             $rows = $db->arrayQuery($query);
             // Some sanity checking
             if (count($rows) == 0) {
                 if ($reportErrors) {
                     eZDebug::writeError("The link ID {$linkID} does not exist, cannot create the link", __METHOD__);
                 }
                 return array('status' => eZURLAliasML::LINK_ID_NOT_FOUND);
             }
             if ($rows[0]['action'] != $action) {
                 if ($reportErrors) {
                     eZDebug::writeError("The link ID {$linkID} uses a different action ({$rows[0]['action']}) than the requested action ({$action}) for the link, cannot create the link", __METHOD__);
                 }
                 return array('status' => eZURLAliasML::LINK_ID_WRONG_ACTION);
             }
             // If the element which is pointed to is a link, then grab the link id from that instead
             if ($rows[0]['link'] != $rows[0]['id']) {
                 $linkID = (int) $rows[0]['link'];
             }
         } else {
             $linkID = null;
         }
         if ($cleanupElements) {
             $topElement = eZURLAliasML::convertToAlias($topElement, 'noname' . (count($createdPath) + 1));
         }
         $adjustName = false;
         $curElementID = null;
         $newText = $topElement;
         $uniqueCounter = 0;
         $rows = null;
         // Will be filled in by the while loop
         // Loop until we a valid entry point, which means:
         // 1. The entry does not exist yet, so create a new one
         // 2. The entry exists but is re-usable (e.g. nop or same action)
         // 3. The entry exists and cannot be re-used, instead the name is adjusted to be unique.
         while (true) {
             $newText = $topElement;
             if ($uniqueCounter > 0) {
                 $newText .= $uniqueCounter + 1;
             }
             $textMD5 = eZURLAliasML::md5($db, $newText);
             $query = "SELECT * FROM ezurlalias_ml WHERE parent = {$parentID} AND text_md5 = {$textMD5}";
             $rows = $db->arrayQuery($query);
             if (count($rows) == 0) {
                 // No such entry, create a new one
                 break;
             }
             $row = $rows[0];
             $curID = (int) $row['id'];
             $curLink = (int) $row['link'];
             $curAction = $row['action'];
             if ($curAction == $action) {
                 // If the current node is the same action and is not a link we
                 // cannot replace it with a link node.
                 if ($curID != $curLink) {
                     // We can reuse the element so record the ID
                     $curElementID = $curID;
                     break;
                 }
             } else {
                 if ($curAction == 'nop:' || $row['is_original'] == 0) {
                     // We can reuse the element so record the ID
                     $curElementID = $curID;
                     break;
                 }
             }
             if (!$autoAdjustName) {
                 if ($reportErrors) {
                     eZDebug::writeError("Tried to store path '{$path}' but the path already exists (ID: {$curID}) but with action '{$curAction}', the new action was '{$action}'");
                 }
                 return array('status' => self::LINK_ALREADY_TAKEN, 'path' => $path, 'element' => null);
             }
             // Need to adjust name, re-iterate
             ++$uniqueCounter;
         }
         $textEsc = $db->escapeString($newText);
         // Create or update the element
         if ($curElementID !== null) {
             $element = new eZURLAliasML($rows[0]);
             // $rows is from the while loop
             $element->LangMask |= $languageID | $alwaysMask;
             $element->IsAlias = 1;
             $element->Action = $action;
             // Note: The `text` field is updated too, this ensures case-changes are stored.
             $element->Text = $newText;
             $element->TextMD5 = null;
             $element->ActionType = null;
             $element->Link = null;
         } else {
             $element = new eZURLAliasML(array('id' => null, 'link' => null, 'parent' => $parentID, 'text' => $newText, 'lang_mask' => $languageID | $alwaysMask, 'action' => $action, 'is_alias' => 1));
         }
         $element->AliasRedirects = $aliasRedirects ? 1 : 0;
         $element->store();
         $createdPath[] = $topElement;
         $createdElement = $element;
     }
     return array('status' => true, 'path' => join("/", $createdPath), 'element' => $createdElement);
 }
 /**
  * Decodes $langMask into all languages it comprises and whether or not
  * the language mask signifies always available or not.
  *
  * The constituent languages are returned as an array of language ids. If
  * the second parameter, $returnLanguageLocale is set to TRUE, locale-codes
  * are used instead of language ids.
  *
  * @param int $langMask
  * @param boolean $returnLanguageLocale
  * @return array
  */
 public static function decodeLanguageMask($langMask, $returnLanguageLocale = false)
 {
     $maxNumberOfLanguges = self::maxCount();
     $maxInteger = pow(2, $maxNumberOfLanguges);
     $list = array();
     // Applying this bit-logic on negative numbers, or numbers out of bounds
     // will have unexpected results.
     if ($langMask < 0 or $langMask > $maxInteger or $langMask == 1) {
         // We use the default language if the situation above occurs
         $defaultLanguage = eZContentLanguage::topPriorityLanguage();
         $langMask = $defaultLanguage->attribute('id');
     }
     $alwaysAvailable = $langMask % 2;
     $mask = $langMask & ~1;
     // Calculating which translations are present in the current version
     for ($i = 1; $i < $maxNumberOfLanguges; ++$i) {
         $newMask = 1 << $i;
         if (($newMask & $mask) > 0) {
             if ($returnLanguageLocale) {
                 $list[] = eZContentLanguage::fetch($newMask)->attribute('locale');
             } else {
                 $list[] = $newMask;
             }
         }
     }
     return array('always_available' => $alwaysAvailable, 'language_list' => $list);
 }
예제 #5
0
$db = eZDB::instance();
$db->begin();
$locales = eZContentLanguage::fetchLocaleList();
$localeToUse = false;
$localeIDToUse = false;
// this script inserts English names, so preferably use an English locale
$preferredLocales = array('eng-GB', 'eng-US');
foreach ($preferredLocales as $preferredLocale) {
    if (in_array($preferredLocale, $locales)) {
        $localeToUse = $preferredLocale;
        break;
    }
}
// when none of the preferred locales are in use, then use the top priority language
if ($localeToUse === false) {
    $prioritizedLanguage = eZContentLanguage::topPriorityLanguage();
    $localeToUse = $prioritizedLanguage->attribute('locale');
}
$lockGroup = new eZContentObjectStateGroup(array('identifier' => 'ez_lock'));
$trans = $lockGroup->translationByLocale($localeToUse);
$trans->setAttribute('name', 'Lock');
$trans->setAttribute('description', 'Lock group');
$messages = array();
if ($lockGroup->isValid($messages)) {
    $cli->output('storing state group ez_lock');
    $lockGroup->store();
} else {
    eZDebug::writeDebug($messages);
    $db->rollback();
    $script->shutdown(2);
}
    /**
     * @return string|bool
     */
    static function defaultLanguage()
    {
        if ( ! isset( $GLOBALS['eZContentObjectDefaultLanguage'] ) )
        {
            $defaultLanguage = false;
            $language = eZContentLanguage::topPriorityLanguage();
            if ( $language )
            {
                $defaultLanguage = $language->attribute( 'locale' );
            }
            else
            {
                $ini = eZINI::instance();
                if ( $ini->hasVariable( 'RegionalSettings', 'ContentObjectLocale' ) )
                {
                    $defaultLanguage = $ini->variable( 'RegionalSettings', 'ContentObjectLocale' );
                    eZContentLanguage::fetchByLocale( $defaultLanguage, true );
                }
            }
            $GLOBALS['eZContentObjectDefaultLanguage'] = $defaultLanguage;
        }

        return $GLOBALS['eZContentObjectDefaultLanguage'];
    }
예제 #7
0
 /**
  * Test when a language is added it does not update link fields of history
  * elements in different languages.
  *
  * @todo This test must be updated when @see eZURLAliasML has been updated
  * to not modify lang_mask field of history elements.
  *
  * @DEFINITION: New translations should not update link field of
  *              history entries in another language
  *
  *              This is new defined behaviour in 4.0.1, 4.1.0 and up
  */
 public function testURLAliasTranslationLinkValues()
 {
     $folder = new ezpObject("folder", 2);
     $folder->name = __FUNCTION__;
     $parentObjId = $folder->publish();
     $article = new ezpObject("article", $folder->mainNode->node_id);
     $validNames[0] = "ChildNode";
     $article->title = $validNames[0];
     $article->publish();
     // Building up some url history
     $validNames[1] = "ChildNodeRenamed";
     $article->title = $validNames[1];
     $article->publish();
     $validNames[2] = "ChildNodeRenamedA";
     $article->title = $validNames[2];
     $article->publish();
     $validNames[3] = "ChildNodeRenamedB";
     $article->title = $validNames[3];
     $article->publish();
     // Add translation of parent node
     $newLanguageCode = "nor-NO";
     $newTranslationName = "Norsk ChildNode";
     $trData = array("title" => $newTranslationName);
     $article->addTranslation($newLanguageCode, $trData);
     $db = eZDB::instance();
     $topLanguageId = (int) eZContentLanguage::topPriorityLanguage()->attribute('id');
     $curEngElementSql = self::buildSql(array($article->mainNode->node_id), $topLanguageId, array('is_original' => 1, 'is_alias' => 0));
     $curEngElement = $db->arrayQuery($curEngElementSql);
     // There should only be one result here
     // (since we know that are are no other occurences of the node3
     // we just created)
     self::assertEquals(1, count($curEngElement), "More than one active entry for the current node detected.");
     $curEngId = (int) $curEngElement[0]['id'];
     $historyElementsSql = self::buildSql(array($article->mainNode->node_id), false, array('is_original' => 0, 'is_alias' => 0));
     $possibleHistoryElements = $db->arrayQuery($historyElementsSql);
     // Since lang_mask might not be correct in the first version, we must
     // filter out the ones we know we just created
     foreach ($possibleHistoryElements as $histEl) {
         if (in_array($histEl['text'], $validNames, true)) {
             // We have a history element in the language we want
             // Check that the link is pointint to the correct element
             // We assert all occurences, but only one error is enough for
             // the test to fail
             self::assertEquals((int) $histEl['link'], $curEngId, "Link element does not point to the correct new entry.");
         }
     }
 }
예제 #8
0
            // Class ID
            $tpl->setVariable('class', $class);
            $tpl->setVariable('lock_timeout', $timeOut);
            $Result = array();
            $Result['content'] = $tpl->fetch('design:class/edit_denied.tpl');
            $Result['path'] = array(array('url' => '/class/grouplist/', 'text' => ezpI18n::tr('kernel/class', 'Class groups')));
            if ($mainGroupID !== false) {
                $Result['path'][] = array('url' => '/class/classlist/' . $mainGroupID, 'text' => $mainGroupName);
            }
            $Result['path'][] = array('url' => false, 'text' => $class->attribute('name'));
            return $Result;
        }
    }
} else {
    if (!$EditLanguage) {
        $language = eZContentLanguage::topPriorityLanguage();
        if ($language) {
            $EditLanguage = $language->attribute('locale');
        } else {
            eZDebug::writeError('Undefined default language', 'class/edit.php');
            $Module->setExitStatus(eZModule::STATUS_FAILED);
            return;
        }
    }
    if (is_numeric($GroupID) and is_string($GroupName) and $GroupName != '') {
        $user = eZUser::currentUser();
        $user_id = $user->attribute('contentobject_id');
        $class = eZContentClass::create($user_id, array(), $EditLanguage);
        $class->setName(ezpI18n::tr('kernel/class/edit', 'New Class'), $EditLanguage);
        $class->store();
        $editLanguageID = eZContentLanguage::idByLocale($EditLanguage);
 function defaultLanguage()
 {
     if (!is_object($this->DefaultLanguage)) {
         $this->DefaultLanguage = eZContentLanguage::topPriorityLanguage();
     }
     return $this->DefaultLanguage;
 }
예제 #10
0
파일: index.php 프로젝트: truffo/eep
 private function createClass($displayName, $classIdentifier, $groupIdentifier, $groupId)
 {
     $adminUserObject = eZUser::fetchByName("admin");
     $adminUserObject->loginCurrent();
     $adminUserId = $adminUserObject->attribute('contentobject_id');
     $language = eZContentLanguage::topPriorityLanguage();
     $editLanguage = $language->attribute('locale');
     $class = eZContentClass::create($adminUserId, array(), $editLanguage);
     // this is the display name, ez automatically creates the content-class-identifier from it
     $class->setName($displayName, $editLanguage);
     $class->setAttribute("identifier", $classIdentifier);
     // default naming for objects - content classes should update this value once they have attributes added
     $class->setAttribute('contentobject_name', 'eep-created-content-class');
     $class->store();
     $editLanguageID = eZContentLanguage::idByLocale($editLanguage);
     $class->setAlwaysAvailableLanguageID($editLanguageID);
     $ClassID = $class->attribute('id');
     $ClassVersion = $class->attribute('version');
     $ingroup = eZContentClassClassGroup::create($ClassID, $ClassVersion, $groupId, $groupIdentifier);
     $ingroup->store();
     // clean up the content class status
     $class->storeDefined(array());
     $adminUserObject->logoutCurrent();
 }