Ejemplo n.º 1
0
    public static function fetch($id)
    {
        $query = '
            SELECT %s, pdf.source as pdf_source, pdf.expiration_duration as pdf_expiration_duration, pdf.media_target as pdf_media_target, pdf.link as pdf_link
            FROM pdf as pdf
            WHERE pdf.id=%s;
        ';

        $result = self::synchronizer()->db->arrayQuery(sprintf($query, implode(', ', self::getQuerySelectFields('pdf')), $id));

        if (!is_array($result) || count($result) == 0)
        {
            throw new MMSynchException('PDF not found');
        }

        $content_row = parent::fetch($result[0]['m_content_id']);

        if (!$content_row)
            return false;

        $instance = new self(array_merge($content_row, $result[0]));

        MMSynchronizer::instance()->placeholder(array(__CLASS__, $id), $instance);

        return $instance;
    }
Ejemplo n.º 2
0
    public static function fetch($id)
    {
        $query = '
            SELECT %s, file.media_target as file_media_target
            FROM file as file
            WHERE file.id=%s;
        ';

        $result = self::synchronizer()->db->arrayQuery(sprintf($query, implode(', ', self::getQuerySelectFields('file')), $id));

        if (!is_array($result) || count($result) == 0)
        {
            throw new MMSynchException('File not found');
        }

        $content_row = parent::fetch($result[0]['m_content_id']);

        if (!$content_row)
            return false;

        $instance = new self(array_merge($content_row, $result[0]));

        MMSynchronizer::instance()->placeholder(array(__CLASS__, $id), $instance);

        return $instance;
    }
    public static function fetch($id)
    {
        $key            = array(__CLASS__, $id);
        $dbEz = self::synchronizer()->ezdb;
        $synchroniser   = MMSynchronizer::instance();
        $publisher      = $synchroniser->placeholder($key);

        if (!$publisher)
        {
            $query = '
                SELECT
                    pf.id as p_id,
                    pf.path as p_path,
                    pf.default_language as pf_default_language,
                    (SELECT t.id FROM mm_taxonomy as t WHERE code = CONCAT("%s-", p_path)) as t_id
                FROM mm_publisher_folder as pf
                WHERE pf.id=%s;
            ';

            $result = $dbEz->arrayQuery(sprintf($query, self::$class_identifier, $id));

            if ((!is_array($result) || count($result) == 0))
            {
                throw new MMSynchException(sprintf('Publisher folder with id %s not found', $id));
            }

            $publisher = new self($result[0]);
            $synchroniser->placeholder($key, $publisher);
        }

        return $publisher;
    }
Ejemplo n.º 4
0
    public static function instance()
    {
        if (!self::$instance)
            self::$instance = new self();

        return self::$instance;
    }
Ejemplo n.º 5
0
    public static function fetch($id, $origin)
    {
        self::$origin = $origin;

        $query = '
            SELECT %s, html_media.headline as html_media_headline, html_media.file as html_media_file, html_media.language as html_media_language, html_media.html_content as html_media_html_content
            FROM html_media as html_media
            WHERE html_media.id=%s;
        ';

        $result = self::synchronizer()->db->arrayQuery(sprintf($query, implode(', ', self::getQuerySelectFields('html_media')), $id));

        if (!is_array($result) || count($result) == 0)
        {
            throw new MMSynchException('HTML Media not found');
        }

        $content_row = parent::fetch($result[0]['m_content_id']);

        $instance = new self(array_merge($content_row, $result[0]));

        MMSynchronizer::instance()->placeholder(array(__CLASS__, $id), $instance);

        return $instance;
    }
Ejemplo n.º 6
0
    public static function fetch($id)
    {
        $query = '
            SELECT ts.name as ts_name, t.name as t_name, t.source_key as t_source_key
            FROM taxonomy as t
            INNER JOIN taxonomy_source as ts ON t.taxonomy_source_id = ts.id
            WHERE t.id=%s;';

        $result = MMSynchronizer::instance()->db->arrayQuery(sprintf($query, $id));

        if (!is_array($result) || count($result) == 0)
        {
            throw new MMSynchException(sprintf('Tag with id %s not found', $id));
        }

        if ($result[0]['t_source_key'] == '')
        {
            throw new MMSynchException(sprintf('Tag %s => %s/%s has no source_key', $id, $result['ts_name'], $result['t_name']));
        }

        return new self($result[0]);
    }
Ejemplo n.º 7
0
    public function __construct(SQLIImportHandlerOptions $options = null)
    {
        parent::__construct($options);

        if (isset($this->options['debug']) && $this->options['debug'] == '1')
        {
            MMSynchLog::$cli    = $this->cli;
            MMSynchLog::$level  = 4;
        }
        else
        {
            MMSynchLog::$level = 3;
        }

        $this->synchronizer = MMSynchronizer::instance();
        
        $archive = $this->synchronizer->archive;

        if (isset($this->options['test']) && $this->options['test'] == '1')
        {
            $this->cli->warning('Test mode enabled : import_status not fill');
            $this->synchronizer->test = true;
            $archive = false;
        }
        
        if (!$archive || isset($this->options['archive']))
        {
            if ($this->options['archive'] == '1') {
                $this->cli->warning('Archiving enabled');
                $archive = true;
            } elseif (!$archive || $this->options['archive'] == '0') {
                $this->cli->warning('Archiving disabled');
                $archive = false;
            }
        }
        
        $this->synchronizer->archive = $archive;
    }
        (
            SELECT GROUP_CONCAT(rc.content_id2 ORDER BY rc.content_order ASC SEPARATOR \',\')
            FROM related_content as rc
            WHERE content_id1 = c.id AND language_id1 = a_language
        ) as a_related_ordered
    FROM article as a
    INNER JOIN content as c ON a.content_id = c.id
    INNER JOIN related_content as related ON c.id = related.content_id1
    INNER JOIN publisher_folder as p ON c.publisher_folder_id = p.id
    INNER JOIN import_status as st ON a.id = st.article_id
    HAVING st_version=st_last_version
    AND a_related != a_related_ordered
    AND a_related != CONCAT_WS(\',\', a_related, a_related);
';

$result = MMSynchronizer::instance()->db->arrayQuery($query);

$cli->output(sprintf('%s article to check', count($result)));

while(list(,$row) = each($result))
{
    $article = false;

    try
    {
        $db->begin();

        $article = MMSynchArticle::fetch($row['a_id']);

        if ($article)
        {
Ejemplo n.º 9
0
<?php

// Use admin
$user   = eZUser::fetchByName('admin');
$userID = $user->attribute( 'contentobject_id' );
eZUser::setCurrentlyLoggedInUser( $user, $userID );

$options = array(
    'modification_check'    => false,
    'update_null_field'     => true
);

SQLIContentPublisher::getInstance()->setOptions(new SQLIContentPublishOptions($options));

$synchronizer   = MMSynchronizer::instance();
$result         = $synchronizer->db->arrayQuery('SELECT ts.id as ts_id, ts.name as ts_name FROM taxonomy_source as ts;');

while(list(,$row) = each($result))
{
    try
    {
        $tag = MMSynchTag::create($row['ts_id'], $row['ts_name']);

        $identifier = str_replace('&', '_', str_replace(' ', '_', strtolower($row['ts_name'])));

        $cli->output('[' . $identifier . ']');
        $cli->output('TagId=' . $tag->attribute( 'id' ));
        $cli->output('TaxonomyId=' . $row['ts_id']);
        $cli->output();
    }
    catch (Exception $e)
    protected function media($attributes, $text, $tagName, $html, $embed = true)
    {
        if ( !isset($attributes['src']) || !isset($attributes['folder']) || !in_array($attributes['folder'], array('audio', 'videos')) )
        {
            throw new MMSynchException(sprintf('Mal formed media tag in core_content %s', $html));
        }

        $ids = array();
        if ( $attributes['folder'] == 'audio' && $this->article->source['a_related_inline_audio'] != "" )
        {
            $tableName = 'audio';
            $ids = explode(',', $this->article->source['a_related_inline_audio']);
        }
        elseif ( $attributes['folder'] == 'videos' && $this->article->source['a_related_inline_video'] != "" )
        {
            $tableName = 'video';
            $ids = explode(',', $this->article->source['a_related_inline_video']);
        }

        if ( count($ids) > 0 )
        {
            $filenamePos = strrpos($attributes['src'], '/');
            $fileName = substr($attributes['src'], $filenamePos ? $filenamePos + 1 : 0);

            $sql = '
                SELECT media.id as id, media.content_id as c_id, media.file as file, media.screen_capture as screen_capture, media.language as language
                FROM %s as media
                INNER JOIN content as c ON media.content_id = c.id
                WHERE media.id IN (%s) AND media.file like "%s";
            ';

            $result = MMSynchronizer::instance()->db->arrayQuery(sprintf($sql, $tableName, implode(',', $ids), '%' . $fileName));

            $screen_capture = null;
            
            if ( isset($attributes['screen_capture']) && $attributes['screen_capture'] != '' )
            {
                try
                {
                    $file = MMSynchFileManager::fromFileName($this->article->getOrigin(), $this->article->getPublisher(), MMSynchFileManager::IMAGE_FOLDER, $attributes['screen_capture']);
                    $screen_capture = file_get_contents($file->getFullPath());
                    $file->setCanArchived();
                }
                catch ( Exception $e )
                {
                    $this->article->addWarning($e->getMessage());
                }
            }

            while ( list(, $row) = each($result) )
            {
                if ( $tableName == 'audio' )
                {
                    $media = MMSynchMediaAudio::fetch($row['id']);
                    if($screen_capture)
                    {
                        $media->source['audio_screen_capture'] = $screen_capture;
                    }
                    elseif($row['screen_capture'])
                    {
                        $media->source['audio_screen_capture'] = $row['screen_capture'];
                    }
                }
                else
                {
                    $media = MMSynchMediaVideo::fetch($row['id']);
                    if($screen_capture)
                    {
                        $media->source['video_screen_capture'] = $screen_capture;
                    }
                    elseif($row['screen_capture'])
                    {
                        $media->source['video_screen_capture'] = $row['screen_capture'];
                    }
                }

                $content = $media->getContent();

                if ( !$content instanceof SQLIContent )
                {
                    throw new MMSynchException(sprintf('Media with id %s not synchronized', $row['id']));
                }

                if ( isset($attributes['view']) && $attributes['view'] == 'inline' )
                {
                    $replacement = '<embed-inline view="embed-inline" size="medium" id="eZObject_%s" />';
                }
                else
                {
                    $replacement = '<embed view="embed" size="medium" id="eZObject_%s" />';
                }

                $this->addRelatedMedia($content->attribute('id'), $row['language']);

                if($embed)
                {
                    return sprintf($replacement, $content->attribute('id'));
                }
                else
                {
                    return $content->attribute('id');
                }
            }
        }

        throw new MMSynchException(sprintf('Media with filename %s not have media table row', $attributes['src']));
    }
Ejemplo n.º 11
0
    public function archive()
    {
        if ($this->archived)
            return true;

        if (!$this->getCanArchived())
        {
            throw new MMSynchException(sprintf('File "%s" not ready to be archived', $this->getFullPath()));
        }

        if (MMSynchronizer::instance()->archive == false)
        {
            $moved = true;
        }
        else
        {
            $importINI = eZINI::instance('sqliimport.ini');
            $modeUAT = false;
            if ( $importINI->hasVariable( 'XMLImportSettings', 'ModeUAT' )
                 && $importINI->variable( 'XMLImportSettings', 'ModeUAT' ) == 'enabled' )
            {
                $modeUAT = true;
            }

            if ( $modeUAT )
            {
                $moved = copy($this->getFullPath(), $this->getArchivePath());
            }
            else
            {
                $moved = rename($this->getFullPath(), $this->getArchivePath());
            }

        }

        if ($moved === false)
        {
            throw new Exception(sprintf('Fail to move "%s" to archive file "%s"', $this->fullPath, $this->getArchivePath()));
        }
        else
        {
            MMSynchLog::debug(false, sprintf('Archive %s to %s', $this->getFullPath(), $this->getArchivePath()));
        }

        $this->archived = true;

        return true;
    }
Ejemplo n.º 12
0
// Configure publisher
SQLIContentPublisher::getInstance()->setOptions(new SQLIContentPublishOptions(array(
    'modification_check' => false,
    'update_null_field'  => false
)));

MMSynchMonitor::start();

// Import one article
unlink($lockFileName);
try
{
    $db->begin();

    MMSynchronizer::instance()->test = true;

    $article = MMSynchArticle::import($options['article'], $options['force']);

    if ($article)
    {
        $cli->output('Node Id = ' . $article->getContent()->defaultLocation->getNodeId());
    }

    $db->commit();
    $iteration++;
}
catch (Exception $e)
{
    $db->rollback();
    $cli->error($e->getMessage());
Ejemplo n.º 13
0
 protected static function synchronizer()
 {
     return MMSynchronizer::instance();
 }
    public function process( $row )
    {
        $db = eZDB::instance();

        // Récupéraiton de l'article
        $article        = MMSynchArticle::fetch($row['a_id']);
        $contentObject  = eZContentObject::fetchByRemoteID( $article->remoteId() );

        if (!$contentObject)
        {
            $this->cli->notice(sprintf(' Synchronization problem for Article %s ', $row['a_id']));
            return false;
        }

        // Récupération des publisher_internal_id
        $referenceArticleIds = array();
        if (trim($article->source['a_referencearticleid']) != '')
        {
            $referenceArticleIds = array_unique(explode('|', trim($article->source['a_referencearticleid'])));
        }

        $db->begin();

        try
        {
            if (count($referenceArticleIds) > 0)
            {
                $query = sprintf("
                    SELECT  a.id as a_id
                    FROM    article a,
                            content c
                    WHERE   a.content_id = c.id
                    AND     a.language = '%s'
                    AND     a.publisher_internal_id IN (%s)
                    AND     c.publisher_folder_id = %s
                    ",
                    $row['a_language'],
                    implode(', ', $referenceArticleIds),
                    $article->source['c_publisher_folder_id']
                );
                $referenceArticles = MMSynchronizer::instance()->db->arrayQuery($query);

                if (count($referenceArticles) > 0)
                {
                    $referenceArticlesObjectIds = array();

                    // Fetch des object correspondant au publisher_internal_id
                    while(list(,$referenceArticleRow) = each($referenceArticles))
                    {
                        $referenceArticle       = MMSynchArticle::fetch($referenceArticleRow['a_id']);
                        $referenceContentObject = eZContentObject::fetchByRemoteID( $referenceArticle->remoteId() );

                        if ($referenceContentObject)
                        {
                            $referenceArticlesObjectIds[] = $referenceContentObject->attribute('id');
                        }
                        else
                        {
                            $this->cli->notice(sprintf(' Synchronization problem for Article %s', $referenceArticleRow['a_id']));
                        }
                    }

                    if (count($referenceArticlesObjectIds))
                    {
                        $dataMap    = $contentObject->fetchDataMap(false, $row['a_language']);
                        $attribute  = $dataMap['reference_articles'];

                        $attribute->fromString(implode('-', array_unique($referenceArticlesObjectIds)));
                        $attribute->store();

                        if (count($referenceArticlesObjectIds) == count($referenceArticleIds))
                        {
                            $this->updateStatus($row);
                        }
                        else
                        {
                            $this->cli->notice(sprintf(' Relationships among the missing publisher_internal_id %s', implode(', ', $referenceArticleIds)));
                        }
                    }
                }
                else
                {
                    $this->cli->notice(sprintf(' No items synchronized among publisher_internal_id %s', implode(', ', $referenceArticleIds)));
                }
            }
            else
            {
                $dataMap    = $contentObject->fetchDataMap(false, $row['a_language']);
                $attribute  = $dataMap['reference_articles'];

                if ($attribute && $attribute->hasContent())
                {
                    $attribute->fromString('');
                    $attribute->store();
                }

                $this->updateStatus($row);
            }

            $db->commit();
        }
        catch (Exception $e)
        {
            $db->rollback();
        }

        eZContentObject::clearCache();
    }