Checks if given $languageMask consists of multiple languages.
public isLanguageMaskComposite ( integer $languageMask ) : boolean | ||
$languageMask | integer | |
Результат | boolean |
/** * Updates "always available" flag for Content identified by $contentId, in respect to * Content's current main language and optionally new $alwaysAvailable state. * * @param int $contentId * @param bool|null $alwaysAvailable New "always available" value or null if not defined */ public function updateAlwaysAvailableFlag($contentId, $alwaysAvailable = null) { // We will need to know some info on the current language mask to update the flag // everywhere needed $contentInfoRow = $this->loadContentInfo($contentId); if (!isset($alwaysAvailable)) { $alwaysAvailable = (bool) $contentInfoRow['language_mask'] & 1; } /** @var $q \eZ\Publish\Core\Persistence\Database\UpdateQuery */ $q = $this->dbHandler->createUpdateQuery(); $q->update($this->dbHandler->quoteTable('ezcontentobject'))->set($this->dbHandler->quoteColumn('language_mask'), $alwaysAvailable ? $q->expr->bitOr($this->dbHandler->quoteColumn('language_mask'), 1) : $q->expr->bitAnd($this->dbHandler->quoteColumn('language_mask'), -2))->where($q->expr->eq($this->dbHandler->quoteColumn('id'), $q->bindValue($contentId, null, \PDO::PARAM_INT))); $q->prepare()->execute(); // Now we need to update ezcontentobject_name /** @var $qName \eZ\Publish\Core\Persistence\Database\UpdateQuery */ $qName = $this->dbHandler->createUpdateQuery(); $qName->update($this->dbHandler->quoteTable('ezcontentobject_name'))->set($this->dbHandler->quoteColumn('language_id'), $alwaysAvailable ? $qName->expr->bitOr($this->dbHandler->quoteColumn('language_id'), 1) : $qName->expr->bitAnd($this->dbHandler->quoteColumn('language_id'), -2))->where($qName->expr->lAnd($qName->expr->eq($this->dbHandler->quoteColumn('contentobject_id'), $qName->bindValue($contentId, null, \PDO::PARAM_INT)), $qName->expr->eq($this->dbHandler->quoteColumn('content_version'), $qName->bindValue($contentInfoRow['current_version'], null, \PDO::PARAM_INT)))); $qName->prepare()->execute(); // Now update ezcontentobject_attribute for current version // Create update query that will be reused /** @var $qAttr \eZ\Publish\Core\Persistence\Database\UpdateQuery */ $qAttr = $this->dbHandler->createUpdateQuery(); $qAttr->update($this->dbHandler->quoteTable('ezcontentobject_attribute'))->where($qAttr->expr->lAnd($qAttr->expr->eq($this->dbHandler->quoteColumn('contentobject_id'), $qAttr->bindValue($contentId, null, \PDO::PARAM_INT)), $qAttr->expr->eq($this->dbHandler->quoteColumn('version'), $qAttr->bindValue($contentInfoRow['current_version'], null, \PDO::PARAM_INT)))); // If there is only a single language, update all fields and return if (!$this->languageMaskGenerator->isLanguageMaskComposite($contentInfoRow['language_mask'])) { $qAttr->set($this->dbHandler->quoteColumn('language_id'), $alwaysAvailable ? $qAttr->expr->bitOr($this->dbHandler->quoteColumn('language_id'), 1) : $qAttr->expr->bitAnd($this->dbHandler->quoteColumn('language_id'), -2)); $qAttr->prepare()->execute(); return; } // Otherwise: // 1. Remove always available flag on all fields $qAttr->set($this->dbHandler->quoteColumn('language_id'), $qAttr->expr->bitAnd($this->dbHandler->quoteColumn('language_id'), -2)); $qAttr->prepare()->execute(); // 2. If Content is always available set the flag only on fields in main language if ($alwaysAvailable) { $qAttr->set($this->dbHandler->quoteColumn('language_id'), $qAttr->expr->bitOr($this->dbHandler->quoteColumn('language_id'), 1)); $qAttr->where($qAttr->expr->gt($qAttr->expr->bitAnd($this->dbHandler->quoteColumn('language_id'), $qAttr->bindValue($contentInfoRow['initial_language_id'], null, PDO::PARAM_INT)), $qAttr->bindValue(0, null, PDO::PARAM_INT))); $qAttr->prepare()->execute(); } }