/** * Performs the publishing operations required to set the version identified by $updateStruct->versionNo and * $updateStruct->id as the published one. * * @param int $contentId * @param int $versionNo * @param \eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct $metaDataUpdateStruct * * @return \eZ\Publish\SPI\Persistence\Content The published Content */ public function publish($contentId, $versionNo, MetadataUpdateStruct $metaDataUpdateStruct) { // Change Content currentVersionNo to the published version $this->backend->update('Content', $contentId, array('_currentVersionNo' => $versionNo)); // Update ContentInfo published flag and change the currentVersionNo to the published version $contentInfoUpdateData = array("currentVersionNo" => $versionNo, "isPublished" => true); // Update ContentInfo with set properties in $metaDataUpdateStruct foreach ($metaDataUpdateStruct as $propertyName => $propertyValue) { if (isset($propertyValue)) { if ($propertyName === "alwaysAvailable") { $contentInfoUpdateData["alwaysAvailable"] = $propertyValue; } else { if ($propertyName === "mainLanguageId") { $contentInfoUpdateData["mainLanguageCode"] = $this->handler->contentLanguageHandler()->load($propertyValue)->languageCode; } else { $contentInfoUpdateData[$propertyName] = $propertyValue; } } } } $this->backend->update('Content\\ContentInfo', $contentId, $contentInfoUpdateData, true); // Update VersionInfo with modified timestamp and published status $this->backend->updateByMatch('Content\\VersionInfo', array('_contentId' => $contentId, 'versionNo' => $versionNo), array("modificationDate" => $metaDataUpdateStruct->modificationDate, "status" => VersionInfo::STATUS_PUBLISHED)); return $this->load($contentId, $versionNo); }
/** * Generate match array for use with Backend based on criteria * * @param array $criteria * @param array $match * * @return void */ protected function generateMatchByCriteria(array $criteria, array &$match) { foreach ($criteria as $criterion) { if ($criterion instanceof LogicalAnd) { $this->generateMatchByCriteria($criterion->criteria, $match); } else { if ($criterion instanceof LogicalOr && !isset($match['or'])) { foreach ($criterion->criteria as $subCriterion) { $subMatch = array(); $this->generateMatchByCriteria(array($subCriterion), $subMatch); $match['or'][] = $subMatch; } } else { if ($criterion instanceof ContentId && !isset($match['id'])) { $match['id'] = $criterion->operator === Operator::IN ? $criterion->value : $criterion->value[0]; } else { if ($criterion instanceof ContentTypeId && !isset($match['versionInfo']['contentInfo']['typeId'])) { $match['versionInfo']['contentInfo']['contentTypeId'] = $criterion->operator === Operator::IN ? $criterion->value : $criterion->value[0]; } else { if ($criterion instanceof LocationId && !isset($match['locations']['id'])) { $match['locations']['id'] = $criterion->operator === Operator::IN ? $criterion->value : $criterion->value[0]; } else { if ($criterion instanceof RemoteId && !isset($match['versionInfo']['contentInfo']['remoteId'])) { $match['versionInfo']['contentInfo']['remoteId'] = $criterion->operator === Operator::IN ? $criterion->value : $criterion->value[0]; } else { if ($criterion instanceof LocationRemoteId && !isset($match['locations']['remoteId'])) { $match['locations']['remoteId'] = $criterion->operator === Operator::IN ? $criterion->value : $criterion->value[0]; } else { if ($criterion instanceof ObjectStateId && !isset($match['objectStates']['id'])) { $match['objectStates']['id'] = $criterion->operator === Operator::IN ? $criterion->value : $criterion->value[0]; } else { if ($criterion instanceof LanguageCode && !isset($match['versionInfo']['languageIds'])) { $languageHandler = $this->handler->contentLanguageHandler(); $languageIds = array_map(function ($languageCode) use($languageHandler) { return $languageHandler->loadByLanguageCode($languageCode)->id; }, $criterion->value); $match['versionInfo']['languageIds'] = $criterion->operator === Operator::IN ? $languageIds : $languageIds[0]; } else { if ($criterion instanceof SectionId && !isset($match['versionInfo']['contentInfo']['sectionId'])) { $match['versionInfo']['contentInfo']['sectionId'] = $criterion->operator === Operator::IN ? $criterion->value : $criterion->value[0]; } else { if ($criterion instanceof Status && !isset($match['versionInfo']['status'])) { switch ($criterion->value[0]) { case Status::STATUS_ARCHIVED: $match['versionInfo']['status'] = VersionInfo::STATUS_ARCHIVED; break; case Status::STATUS_DRAFT: $match['versionInfo']['status'] = VersionInfo::STATUS_DRAFT; break; case Status::STATUS_PUBLISHED: $match['versionInfo']['status'] = VersionInfo::STATUS_PUBLISHED; break; default: throw new Exception("Unsupported StatusCriterion->value[0]: " . $criterion->value[0]); } } else { if ($criterion instanceof ParentLocationId && !isset($match['locations']['parentId'])) { $match['locations']['parentId'] = $criterion->operator === Operator::IN ? $criterion->value : $criterion->value[0]; } else { if ($criterion instanceof Subtree && !isset($match['locations']['pathString'])) { $match['locations']['pathString'] = $criterion->value[0] . '%'; } else { if ($criterion instanceof UserMetadata && $criterion->target !== $criterion::MODIFIER) { if ($criterion->target === $criterion::OWNER && !isset($match['versionInfo']['contentInfo']['ownerId'])) { $match['versionInfo']['contentInfo']['ownerId'] = $criterion->operator === Operator::IN ? $criterion->value : $criterion->value[0]; } else { if ($criterion->target === $criterion::CREATOR && !isset($match['versionInfo']['creatorId'])) { $match['versionInfo']['creatorId'] = $criterion->operator === Operator::IN ? $criterion->value : $criterion->value[0]; } } //else if ( $criterion->target === $criterion::MODIFIER && !isset( $match['version']['creatorId'] ) ) //$match['version']['creatorId'] = $criterion->value[0]; continue; } throw new Exception("Support for provided criterion not supported or used more then once: " . get_class($criterion)); } } } } } } } } } } } } } } }