Ejemplo n.º 1
0
    /**
     * @param string $filepath [publisher_path]/[folder]/filename.ext
     * @param MMSynchPublisherFolder $publisher
     * @param string $folder
     * @return MMSynchFile
     * @throws MMSynchException
     */
    public static function fromRoot(MMSynchPublisherFolder $publisher, $folder, $filepath)
    {
        $pos    = strpos($filepath, '/');
        $origin = substr($filepath, 0, $pos);
        $root   = $origin . '/' . $publisher->getFolder() . '/' . $folder . '/';
        $pos    = strpos($filepath, $root);

        if ($pos !== 0)
        {
            throw new MMSynchException(sprintf('File path from root "%s" not found (expected root: %s)', $filepath, $root));
        }

        $filepath = substr($filepath, $pos + strlen($root));

        return self::createFile($origin, $publisher, $folder, $filepath);
    }
Ejemplo n.º 2
0
    public function __construct($origin, MMSynchPublisherFolder $publisher, $folder, $filename)
    {
        $this->origin = $origin;

        // Publisher part
        $this->publisherFolder = $publisher->getFolder();

        // Folder part
        $this->folder = $folder;

        // File part
        $this->fileName = $filename;

        if (substr($this->fileName, 0, 1) == '/')
            $this->fileName = substr($this->fileName, 1);

        // Full path
        $fullPathParts = array(
            MMSynchFileManager::getRootPath(),
            $this->origin,
            $this->publisherFolder,
            $this->folder,
            $this->fileName
        );

        $this->fullPath = implode('/', $fullPathParts);

        if (!is_file($this->fullPath))
        {
            $archivePath = $this->getArchivePath();

            if (is_file($archivePath))
            {
                MMSynchLog::warning(sprintf('File "%s" is archived', $this->fullPath));

                $this->fullPath = $archivePath;
                $this->archived = true;
            }
            else
            {
                throw new MMSynchException(sprintf('File "%s" not exist and is not archived', $this->fullPath));
            }
        }
    }
Ejemplo n.º 3
0
    public function getPublisher()
    {
        if (!$this->source['p_id'])
            throw new MMSynchException('Variable "p_id" not set in source');

        if (!$this->publisher)
        {
            $this->publisher = MMSynchPublisherFolder::fetch($this->source['p_id']);
        }

        return $this->publisher;
    }
Ejemplo n.º 4
0
    protected function synchronize()
    {
        parent::synchronize();

        $locale         = $this->source['m_language'];
        $this->content  = SQLIContent::create(new SQLIContentOptions( array(
            'class_identifier'      => self::$class_identifier,
            'remote_id'             => $this->remoteId(),
            'language'              => $locale
        )));

        // Positionnement sous le publisher
        $publisher = MMSynchPublisherFolder::fetch($this->source['p_id']);
        MMSynchHelper::addLocation($this->content, $publisher->getContentMediaFile()->defaultLocation);

        if (!isset($this->content->fields[$locale]))
            $this->content->addTranslation($locale);

        $this->content->setActiveLanguage($locale);

        $this->populate();
        $this->publish();
    }
/**
 * Adds an application folder to the publisher folder if it's not yet added
 * @param mixed $applicationId
 * @param mixed $publisherFolderId
 * @param eZCLI $cli
 */
function alignApplicationWithPublisherFolder( $applicationId, $publisherFolderId, eZCLI $cli )
{
    $application = $applicationId;
    $publisherFolder = $publisherFolderId;
    if (! $application instanceof ApplicationLocalized )
    {
        $application = ApplicationLocalized::getLocalizedApplicationById( $applicationId, false );
    }
    if ( $application == null )
    {
        throw new Exception( "Application localized with id {$applicationId} does not exist." );
    }

    if (! $publisherFolder instanceof MMSynchPublisherFolder )
    {
        $publisherFolder = MMSynchPublisherFolder::fetch( $publisherFolderId );
    }
    if ( $publisherFolder == null )
    {
        throw new Exception( "Publisher folder with id {$publisherFolderId} does not exist." );
    }

    $remoteId = 'application_folder-' . $application->cluster_identifier . '-' . $application->applicationObject->identifier;
    $applicationFolderObject = eZContentObject::fetchByRemoteID( $remoteId );
    if ( $applicationFolderObject == null )
    {
        throw new Exception( "Application folder object with remote id {$remoteId} doesn't exist" );
    }

    $applicationFolderId = $applicationFolderObject->attribute( 'id' );
    //use getContent with true to create problems
    $path = $publisherFolder->getContent( )->fields->path->toString();
    if ( $path )
    {
        $contentobject = $publisherFolder->getContent()->getRawContentObject();

        $languages = $contentobject->availableLanguages();

        foreach ( $languages as $language )
        {
            $dataMap = $contentobject->dataMap();
            $contentObjectAttributeTargetCS = $dataMap['target_cs'];
            $objectIds = explode( '-', $contentObjectAttributeTargetCS->toString() );

            if ( !in_array( $applicationFolderId, $objectIds ) )
            {
                $objectIds[] = $applicationFolderId;
                $contentObjectAttributeTargetCS->fromString( implode( '-', $objectIds ) );
                $contentObjectAttributeTargetCS->store();
            } 
            else
            {
                $cli->notice( "Ommiting application folder with path {$remoteId}" );
            }
        }
    }
}
    {
        $replies = $cli->askQuestionMultipleChoices(
            'Choose publisher folders you want to create',
            $folders,
            'validateReplyMultiple',
            true
        );
    }

    if (!empty($replies))
    {
        foreach ($replies as $key)
        {
            try
            {
                $object = MMSynchPublisherFolder::fetch($key);
                $path   = $object->getContent(true)->fields->path->toString();
            }
            catch (Exception $e)
            {
                echo $e->getTraceAsString() . "\n";
                echo "Error : " . $e->getMessage() . "\n";
            }
        }
    }
}
else
{
    echo "No new publisher folder to create\n";
}