Handles export

@param int $contentId

@return \Symfony\Component\HttpFoundation\RedirectResponse|Response
975080
public function exportAllAction($contentId)
    {
        $content = $this->contentService->loadContent($contentId);

        $exportCriteria = new ExportCriteria(
            [
                'content' => $content,
            ]
        );

        $export = $this->exporter->exportAll($exportCriteria);

        $writer = Writer::createFromFileObject(new SplTempFileObject());
        $writer->setDelimiter(",");
        $writer->setNewline("\r\n"); //use windows line endings for compatibility with some csv libraries
        $writer->setOutputBOM(Writer::BOM_UTF8); //adding the BOM sequence on output
        $writer->insertOne($export->header);
        $writer->insertAll($export->contents);

        $writer->output('export.csv');
        return new Response('');

    }
917506
public function countLocationsByContentId($contentId)
    {
        try {
            return $this->innerGateway->countLocationsByContentId($contentId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
552082
public function apply($contentId)
    {
        $versionNumbers = $this->contentGateway->listVersionNumbers($contentId);
        $languageCodeToFieldId = array();

        $nameRows = $this->contentGateway->loadVersionedNameData(
            array_map(
                function ($versionNo) use ($contentId) {
                    return array('id' => $contentId, 'version' => $versionNo);
                },
                $versionNumbers
            )
        );

        foreach ($versionNumbers as $versionNo) {
            $contentRows = $this->contentGateway->load($contentId, $versionNo);
            $contentList = $this->contentMapper->extractContentFromRows($contentRows, $nameRows);
            $content = $contentList[0];
            $languageCodeSet = array();

            // Each subsequent Content version can have additional language(s)
            foreach ($content->fields as $field) {
                $languageCode = $field->languageCode;

                // Add once for each language per version
                if (isset($languageCodeSet[$languageCode])) {
                    continue;
                }

                $languageCodeSet[$languageCode] = true;

                // Check if field was already inserted for current language code,
                // in that case we need to preserve its ID across versions
                if (isset($languageCodeToFieldId[$languageCode])) {
                    $fieldId = $languageCodeToFieldId[$languageCode];
                } else {
                    $fieldId = null;
                }

                $languageCodeToFieldId[$languageCode] = $this->insertField(
                    $content,
                    $this->createField(
                        $fieldId,
                        $versionNo,
                        $languageCode
                    )
                );
            }
        }
    }
478559
public function store(Request $request, $contentId, $blockTypeId)
    {
        try {
            list($content, $blockType, $block) = array_values($this->contentBlocks->save($request, $contentId, $blockTypeId));
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => trans('soda::terminology.block')]));
        }

        return redirect()->route('soda.content.edit', [$contentId, 'tab' => $this->getTab($blockType)])->with('success', trans('soda::messages.created', ['object' => trans('soda::terminology.block')]));
    }
1339846
public function resolveContentId($contentTypeId, $contentId)
    {
        // content type ?
        if (!$contentType = $this->contentTypeLoader->retrieve($contentTypeId)) {
            throw new InvalidContentException(sprintf(
                'No content type registered under "%s" id, check you configuration.',
                $contentTypeId
            ));
        }

        // content object
        if (!$content = $contentType->retrieveContent($contentId)) {
            throw new InvalidContentException(sprintf(
                'Unable to get a "%s" content under "%s" id.',
                $contentType->getName(),
                $contentId
            ));
        }

        return $this->wrap($contentType, $content);
    }
288839
public function deleteContent($contentId)
    {
        $query = $this->dbHandler->createDeleteQuery();
        $query->deleteFrom('ezcontentobject')
            ->where(
                $query->expr->eq(
                    $this->dbHandler->quoteColumn('id'),
                    $query->bindValue($contentId, null, \PDO::PARAM_INT)
                )
            );

        $query->prepare()->execute();
    }
1147610
public function apply($contentId)
    {
        $versionNumbers = $this->contentGateway->listVersionNumbers($contentId);
        $fieldIdSet = array();

        $nameRows = $this->contentGateway->loadVersionedNameData(
            array_map(
                function ($versionNo) use ($contentId) {
                    return array('id' => $contentId, 'version' => $versionNo);
                },
                $versionNumbers
            )
        );

        foreach ($versionNumbers as $versionNo) {
            $contentRows = $this->contentGateway->load($contentId, $versionNo);
            $contentList = $this->contentMapper->extractContentFromRows($contentRows, $nameRows);
            $content = $contentList[0];
            $versionFieldIdSet = array();

            foreach ($content->fields as $field) {
                if ($field->fieldDefinitionId == $this->fieldDefinition->id) {
                    $fieldIdSet[$field->id] = true;
                    $versionFieldIdSet[$field->id] = true;
                }
            }

            // Delete from external storage with list of IDs per version
            $this->storageHandler->deleteFieldData(
                $this->fieldDefinition->fieldType,
                $content->versionInfo,
                array_keys($versionFieldIdSet)
            );
        }

        // Delete from internal storage -- field is always deleted from _all_ versions
        foreach (array_keys($fieldIdSet) as $fieldId) {
            $this->contentGateway->deleteField($fieldId);
        }
    }
1229152
public function createDetailContent($id, $contentData)
    {
        $response = $this->mailjet->post(Resources::$CampaigndraftDetailcontent,
            ['id' => $id, 'body' => $contentData]);
        if (!$response->success()) {
            $this->throwError("CampaignDraftService:createDetailContent failed",
                $response);
        }

        return $response->getData();
    }
1372415
public function deleteContent($contentId)
    {
        $contentLocations = $this->contentGateway->getAllLocationIds($contentId);
        if (empty($contentLocations)) {
            $this->removeRawContent($contentId);
        } else {
            foreach ($contentLocations as $locationId) {
                $this->treeHandler->removeSubtree($locationId);
            }
        }
    }
246618
public function getContentIdsByContentTypeId($contentTypeId)
    {
        $query = $this->dbHandler->createSelectQuery();
        $query
            ->select($this->dbHandler->quoteColumn('id'))
            ->from($this->dbHandler->quoteTable('ezcontentobject'))
            ->where(
                $query->expr->eq(
                    $this->dbHandler->quoteColumn('contentclass_id'),
                    $query->bindValue($contentTypeId, null, PDO::PARAM_INT)
                )
            );

        $statement = $query->prepare();
        $statement->execute();

        return $statement->fetchAll(PDO::FETCH_COLUMN);
    }
777089
public function getContentName($contentId): string
    {
        try {
            $versionInfo = $this->loadVersionInfo($contentId);

            return $versionInfo->getName() ?? '';
        } catch (Throwable $t) {
            return '';
        }
    }
310037
public function getLastVersionNumber($contentId)
    {
        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            $query->expr->max($this->dbHandler->quoteColumn('version'))
        )->from(
            $this->dbHandler->quoteTable('ezcontentobject_version')
        )->where(
            $query->expr->eq(
                $this->dbHandler->quoteColumn('contentobject_id'),
                $query->bindValue($contentId, null, \PDO::PARAM_INT)
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        return (int)$statement->fetchColumn();
    }
49027
public function syncFiles($contentId)
    {
        $block = $this->repository->getById($contentId);
        if (empty($block)) {
            return $this->respondNotFound();
        }
        $this->authorize('update', $block);
        $input = $this->validator->validate('syncFiles');
        $block = $this->fileRepository->syncWith($block, $this->buildSyncData($input));
        return $this->respondWithSuccess($block);
    }
792161
public function updateContentMetadata($contentId, Request $request)
    {
        $updateStruct = $this->inputDispatcher->parse(
            new Message(
                array('Content-Type' => $request->headers->get('Content-Type')),
                $request->getContent()
            )
        );

        $contentInfo = $this->repository->getContentService()->loadContentInfo($contentId);

        // update section
        if ($updateStruct->sectionId !== null) {
            $section = $this->repository->getSectionService()->loadSection($updateStruct->sectionId);
            $this->repository->getSectionService()->assignSection($contentInfo, $section);
            $updateStruct->sectionId = null;
        }

        // @todo Consider refactoring! ContentService::updateContentMetadata throws the same exception
        // in case the updateStruct is empty and if remoteId already exists. Since REST version of update struct
        // includes section ID in addition to other fields, we cannot throw exception if only sectionId property
        // is set, so we must skip updating content in that case instead of allowing propagation of the exception.
        foreach ($updateStruct as $propertyName => $propertyValue) {
            if ($propertyName !== 'sectionId' && $propertyValue !== null) {
                // update content
                $this->repository->getContentService()->updateContentMetadata($contentInfo, $updateStruct);
                $contentInfo = $this->repository->getContentService()->loadContentInfo($contentId);
                break;
            }
        }

        try {
            $locationInfo = $this->repository->getLocationService()->loadLocation($contentInfo->mainLocationId);
        } catch (NotFoundException $e) {
            $locationInfo = null;
        }

        return new Values\RestContent(
            $contentInfo,
            $locationInfo
        );
    }
489
public function createDraftFromCurrentVersion($contentId)
    {
        $contentInfo = $this->repository->getContentService()->loadContentInfo($contentId);
        $contentType = $this->repository->getContentTypeService()->loadContentType($contentInfo->contentTypeId);
        $versionInfo = $this->repository->getContentService()->loadVersionInfo(
            $contentInfo
        );

        if ($versionInfo->isDraft()) {
            throw new ForbiddenException('Current version is already in status DRAFT');
        }

        $contentDraft = $this->repository->getContentService()->createContentDraft($contentInfo);

        return new Values\CreatedVersion(
            array(
                'version' => new Values\Version(
                    $contentDraft,
                    $contentType,
                    $this->repository->getContentService()->loadRelations($contentDraft->getVersionInfo())
                ),
            )
        );
    }
1309735
public function deleteContent($contentId, $versionId = null)
    {
        // 1. Delete the Content
        if ($versionId === null) {
            $this->gateway->deleteByQuery(json_encode(['query' => ['match' => ['_id' => $contentId]]]), $this->contentDocumentTypeIdentifier);
        } else {
            $this->gateway->delete($contentId, $this->contentDocumentTypeIdentifier);
        }

        // 2. Delete all Content's Locations
        $this->gateway->deleteByQuery(json_encode(['query' => ['match' => ['content_id_id' => $contentId]]]), $this->locationDocumentTypeIdentifier);
    }
387771
public function publish($contentTypeId)
    {
        $toType = $this->load($contentTypeId, Type::STATUS_DRAFT);

        try {
            $fromType = $this->load($contentTypeId, Type::STATUS_DEFINED);
            $this->updateHandler->updateContentObjects($fromType, $toType);
            $this->updateHandler->deleteOldType($fromType);
        } catch (Exception\TypeNotFound $e) {
            // If no old type is found, no updates are necessary to it
        }

        $this->updateHandler->publishNewType($toType, Type::STATUS_DEFINED);
    }