/**
  * Main method to process current row returned by getNextRow() method.
  * You may throw an exception if something goes wrong. It will be logged but won't break the import process
  * @param mixed $row Depending on your data format, can be DOMNode, SimpleXMLIterator, SimpleXMLElement, CSV row...
  */
 public function process($row)
 {
     $contentOptions = new SQLIContentOptions(array('class_identifier' => 'user', 'remote_id' => (string) $row->login));
     $content = SQLIContent::create($contentOptions);
     $content->fields->first_name = (string) $row->firstName;
     $content->fields->last_name = (string) $row->lastName;
     $userParts = array((string) $row->login, (string) $row->email);
     //password management : if empty, generate it, use custom default or fixed default
     $password = $row->password;
     if (!$password) {
         if (isset($this->options->generate_password) && $this->options->generate_password) {
             $password = eZUser::createPassword(6);
         } elseif (isset($this->options->default_password) && $this->options->default_password) {
             $password = $this->options->default_password;
         } else {
             $password = '******';
         }
     }
     $userParts[] = $password;
     $userParts[] = eZUser::createHash((string) $row->login, $password, eZUser::site(), eZUser::hashType());
     $userParts[] = eZUser::hashType();
     $content->fields->user_account = implode('|', $userParts);
     // Now publish content
     $content->addLocation(SQLILocation::fromNodeID($this->handlerConfArray['DefaultParentNodeID']));
     $publisher = SQLIContentPublisher::getInstance();
     $publisher->publish($content);
     // Free some memory. Internal methods eZContentObject::clearCache() and eZContentObject::resetDataMap() will be called
     // @see SQLIContent::__destruct()
     unset($content);
     $this->csv->rows->next();
 }
Ejemplo n.º 2
0
    /**
     * Vérifie si un objet à déjà la location donnée
     * Attention cette méthode utilise les locations en cache
     * @param SQLIContent $content
     * @param SQLILocation $parentLocation
     * @return boolean
     */
    public static function isAlreadyLocatedIn(SQLIContent $content, $parentLocation)
    {
        $node_id = $parentLocation;

        if ($parentLocation instanceof SQLILocation)
            $node_id = $parentLocation->getNodeId();

        reset($content->locations);

        foreach($content->locations as $location)
        {
            if ($location->getNodeId() == $node_id)
                return true;
        }

        return false;
    }
 /**
  * (non-PHPdoc)
  * @see extension/sqliimport/classes/sourcehandlers/ISQLIImportHandler::process()
  */
 public function process($row)
 {
     // $row is a SimpleXMLElement object
     $this->currentGUID = $row->guid;
     $contentOptions = new SQLIContentOptions(array('class_identifier' => 'article', 'remote_id' => (string) $row->guid));
     $content = SQLIContent::create($contentOptions);
     $content->fields->title = (string) $row->title;
     $content->fields->author = (string) $row->author . '|noreply@sqli.com|-1';
     // @see eZAuthorType::fromString()
     // Handle HTML content
     $content->fields->intro = $this->getRichContent((string) $row->description);
     // Proxy method to SQLIContentUtils::getRichContent()
     // Now publish content
     $content->addLocation(SQLILocation::fromNodeID($this->handlerConfArray['DefaultParentNodeID']));
     $publisher = SQLIContentPublisher::getInstance();
     $publisher->publish($content);
     // Free some memory. Internal methods eZContentObject::clearCache() and eZContentObject::resetDataMap() will be called
     // @see SQLIContent::__destruct()
     unset($content);
 }
Ejemplo n.º 4
0
 /**
  * (non-PHPdoc)
  * @see extension/sqliimport/classes/sourcehandlers/ISQLIImportHandler::process()
  */
 public function process($row)
 {
     $this->currentID = $row['zupid'];
     $remoteID = 'concert_fb-' . $row['zupid'];
     $reviewOptions = new SQLIContentOptions(array('class_identifier' => self::CONTENT_CLASS, 'remote_id' => $remoteID));
     $content = SQLIContent::create($reviewOptions);
     $publisher = SQLIContentPublisher::getInstance();
     $parentLocation = SQLILocation::fromNodeID($this->handlerConfArray['DefaultParentNodeID']);
     $content->fields->name = (string) $row->name;
     $content->fields->link = (string) $row->deepLink;
     $timestampFrom = strtotime((string) $row->validFrom);
     $timestampTo = strtotime((string) $row->validTo);
     $content->fields->date_from = $timestampFrom;
     $content->fields->date_to = $timestampTo;
     $content->fields->unpublish_date = $timestampTo > 0 ? $timestampTo + 86400 : $timestampFrom + 86400;
     // Dépublication 1j après la date de fin
     $content->fields->price = (string) $row->price . '|1|1';
     $content->fields->currency = (string) $row->currencyCode;
     $content->fields->image_small = (string) $row->smallImage;
     $content->fields->image_medium = (string) $row->mediumImage;
     $content->fields->image_large = (string) $row->largeImage;
     $content->fields->place = (string) $row->manufacturer . ' (' . (string) ucwords($row->extra2) . ')';
     if (strpos((string) $row->shippingHandling, '1|0') === 0) {
         $latitude = '';
         $longitude = '';
     } else {
         list($gps1, $gps2, $latitude, $longitude) = explode('|', (string) $row->shippingHandling);
     }
     $location = '1|#' . $latitude . '|#' . $longitude . '|#' . (string) $row->longDescription . ', ' . (string) $row->extra2 . ', ' . (string) $row->description;
     $content->fields->gmap_location = $location;
     $zip = (string) $row->terms;
     $content->fields->zip_code = $zip;
     $content->fields->region = substr($zip, 0, 2);
     $content->fields->country = (string) $row->description;
     $content->addLocation($parentLocation);
     $publisher->publish($content);
     unset($content);
 }
Ejemplo n.º 5
0
<?php

include 'extension/sqliimport/stubs/scriptinit.php';
eZINI::instance()->setVariable('ContentSettings', 'ViewCaching', 'disabled');
$cli->notice('Creation of a new "comment" object');
$options = new SQLIContentOptions(array('class_identifier' => 'comment', 'remote_id' => 'my_ubber_cool_remote_id', 'language' => 'fre-FR'));
$comment = SQLIContent::create($options);
$cli->notice('Current version : ' . $comment->current_version);
$comment->fields->subject = 'Mon super sujet';
$comment->fields->author = 'Moi !';
$comment->fields->message = 'Le commentaire de la mort';
$comment->addTranslation('eng-US');
$comment->fields['eng-US']->subject = 'My great subject';
$comment->fields['eng-US']->author = 'Batman';
$comment->fields['eng-US']->message = 'Death comment';
$comment->addLocation(SQLILocation::fromNodeID(2));
$comment->addLocation(SQLILocation::fromNodeID(43));
$publisher = SQLIContentPublisher::getInstance();
$publisher->publish($comment);
$cli->notice('Current version : ' . $comment->current_version);
// Loop against locations
foreach ($comment->locations as $nodeID => $location) {
    $cli->notice($nodeID . ' => ' . $location->path_string . ' (' . $comment->locations[$nodeID]->path_identification_string . ')');
}
$script->shutdown();
Ejemplo n.º 6
0
 /**
  * Refreshes locations for content
  * @internal
  */
 public function refreshLocations()
 {
     $this->currentLocations = null;
     $this->currentLocations = new SQLILocationSet();
     $assignedNodes = $this->contentObject->assignedNodes();
     foreach ($assignedNodes as $node) {
         $this->currentLocations->addLocation(SQLILocation::fromNode($node));
     }
 }
 /**
  * (non-PHPdoc)
  * @see extension/sqliimport/classes/sourcehandlers/ISQLIImportHandler::process()
  */
 public function process($row)
 {
     // $row is a SimpleXMLElement object
     $this->currentGUID = $row->id;
     $contentOptions = new SQLIContentOptions(array('class_identifier' => 'blog_post', 'remote_id' => (string) $row->id));
     $content = SQLIContent::create($contentOptions);
     $published = (string) $row->published;
     $updated = (string) $row->updated;
     $skipUpdated = false;
     if ($published && $published != '' && $published != 0) {
         $content->setAttribute('published', strtotime($published));
         $content->store();
     } elseif ((!$published || ${$published} == '' || $published == 0) && ($updated && $updated != '' && $updated != 0)) {
         $content->setAttribute('published', strtotime($updated));
         $content->setAttribute('modified', strtotime($updated));
         $content->store();
         $skipUpdated = true;
     }
     if (!$skipUpdated && $updated && $updated != '' && $updated != 0) {
         $content->setAttribute('modified', strtotime($updated));
         $content->store();
     } elseif (!$skipUpdated && (!$updated || ${$updated} == '' || $updated == 0) && ($published && $published != '' && $published != 0)) {
         $content->setAttribute('published', strtotime($published));
         $content->setAttribute('modified', strtotime($published));
         $content->store();
     }
     $defaultParentNodeID = $this->handlerConfArray['DefaultParentNodeID'];
     $title = (string) $row->title;
     $content->fields->title = $title;
     $content->fields->blog_post_author = (string) $row->author->name;
     $content->fields->blog_post_url = (string) $row->link["href"];
     $content->fields->publication_date = strtotime((string) $row->updated);
     // Handle HTML content
     $message = (string) $row->content;
     $content->fields->blog_post_description_text_block = str_replace('href="/', 'href="http://github.com/', $message);
     // Proxy method to SQLIContentUtils::getRichContent()
     $issueTicketID = $this->getIssueFromGitCommitMessage($title, strip_tags($message));
     // echo "\n\n"; print_r($issueTicketID); echo "\n\n";
     $content->fields->tags = $issueTicketID;
     //echo "\n\nCorrupt-ObjectID: "; print_r( $content->attribute( 'id' ) ); echo "\n\n";
     // Now publish content
     $content->addLocation(SQLILocation::fromNodeID($defaultParentNodeID));
     $publisher = SQLIContentPublisher::getInstance();
     $publisher->publish($content);
     // Clear cache
     $defaultParentNodeID = $this->handlerConfArray['DefaultParentNodeID'];
     $parentNode = eZContentObjectTreeNode::fetch($defaultParentNodeID, 'eng-US');
     if ($parentNode != false) {
         $objectID = $parentNode->attribute('object')->attribute('id');
         eZContentCacheManager::clearContentCacheIfNeeded($objectID);
     }
     // Free some memory. Internal methods eZContentObject::clearCache() and eZContentObject::resetDataMap() will be called
     // @see SQLIContent::__destruct()
     unset($content);
 }
 /**
  * Adds a location to provided content.
  * Prefer using SQLIContent::addLocation() instead of calling this method directly
  * @param SQLILocation $location
  * @param SQLIContent $content
  * @internal
  */
 public function addLocationToContent(SQLILocation $location, SQLIContent $content)
 {
     $nodeID = $content->attribute('main_node_id');
     if (!$nodeID) {
         // No main node ID, object has not been published at least once
         throw new SQLIContentException(__METHOD__ . ' => Cannot directly add a location to a not-yet-published content. Content Object ID = ' . $content->attribute('id') . '. Try to use SQLIContent::addLocation()');
     }
     $objectID = $content->attribute('id');
     $locationNodeID = $location->getNodeID();
     // Check first if content has already an assigned node in provided location
     $assignedNodes = $content->assignedNodes(false);
     for ($i = 0, $iMax = count($assignedNodes); $i < $iMax; ++$i) {
         if ($locationNodeID == $assignedNodes[$i]['parent_node_id']) {
             eZDebug::writeWarning(__METHOD__ . ' => Content with ObjectID #' . $objectID . ' already has a location as a child of node #' . $locationNodeID);
             return;
         }
     }
     eZDebug::accumulatorStart('sqlicontentpublisher_add_location', 'sqlicontentpublisher', 'Adding a location for object #' . $objectID);
     $selectedNodeIDArray = array($locationNodeID);
     if (eZOperationHandler::operationIsAvailable('content_addlocation')) {
         $operationResult = eZOperationHandler::execute('content', 'addlocation', array('node_id' => $nodeID, 'object_id' => $objectID, 'select_node_id_array' => $selectedNodeIDArray), null, true);
     } else {
         eZContentOperationCollection::addAssignment($nodeID, $objectID, $selectedNodeIDArray);
     }
     $content->refreshLocations();
     eZDebug::accumulatorStop('sqlicontentpublisher_add_location');
 }
 public function updateLastcorrectjob()
 {
     try {
         setlocale(LC_TIME, "it_IT");
         date_default_timezone_set('Europe/Rome');
         $dateClientobjectsync = date_create();
         // echo("->timestamp->".date_timestamp_get($date)."<-");
         $timestamp = date_timestamp_get($dateClientobjectsync);
         $dateLastcorrectjobContentOptions = new SQLIContentOptions(array('class_identifier' => 'clientobjectsync', 'remote_id' => 'clientObjectSync-lastcorrectjob'));
         $dateLastcorrectjob = SQLIContent::create($dateLastcorrectjobContentOptions);
         $dateLastcorrectjob->fields->nome = 'MyclientObjectSync';
         // Assegnazione dell'attributo lastcorrectjob
         $dateLastcorrectjob->fields->lastcorrectjob = $timestamp;
         //Prova a recuperare l'ID Nodo: 43 Media [Cartella] dal content.ini
         $contentIni = eZINI::instance('content.ini');
         $idNodoMedia = 43;
         if ($contentIni->hasVariable('NodeSettings', 'MediaRootNode')) {
             $idNodoMedia = $contentIni->variable('NodeSettings', 'MediaRootNode');
         }
         $dateLastcorrectjob->addLocation(SQLILocation::fromNodeID($idNodoMedia));
         $dateLastcorrectjobId = $this->store($dateLastcorrectjob);
     } catch (Exception $exp) {
         echo 'Got Exception message on updateLastcorrectjob: ' . $exp->getMessage() . "\n";
         $this->ocLoggerUtil->addErrorMessage('Exception on objectController -  updateLastcorrectjob: ' . $exp->getMessage());
         $this->ocLoggerUtil->writeLogs();
         return false;
     }
 }
Ejemplo n.º 10
0
    public static function create($options)
    {
        $contentOptions = array();
        if (isset($options['remote_id']))
            $contentOptions['remote_id'] = $options['remote_id'];

        if (isset($options['section_id']))
            $contentOptions['section_id'] = $options['section_id'];

        if (isset($options['creator_id']))
            $contentOptions['creator_id'] = $options['creator_id'];

        if (isset($options['language']))
            $contentOptions['language'] = $options['language'];

        if (isset($options['class_identifier']))
            $contentOptions['class_identifier'] = $options['class_identifier'];

        $content = SQLIContent::create( new SQLIContentOptions($contentOptions) );

        if (isset($contentOptions['language']))
        {
            if (!isset($content->fields[$contentOptions['language']]))
            {
                $content->addTranslation($contentOptions['language']);
            }

            $content->setActiveLanguage($contentOptions['language']);
        }

        if (isset($options['parent_node_id']))
        {
            $location = SQLILocation::fromNodeID( $options['parent_node_id'] );
            $content->addLocation($location);
        }

        if (isset($options['data_map']))
        {
            if (isset($options['data_map']['default']) && is_array($options['data_map']['default']))
            {
                foreach($options['data_map']['default'] as $attributeIdentifier => $attributeString)
                {
                    $content->fields->{$attributeIdentifier} = $attributeString;
                }
            }

            foreach($options['data_map'] as $language => $dataMap)
            {
                if ($language == 'default')
                    continue;

                if (!isset($content[$language]))
                    $content->addTranslation($language);

                foreach($dataMap as $attributeIdentifier => $attributeString)
                {
                    $content->fields[$language]->{$attributeIdentifier} = $attributeString;
                }
            }
        }

        if (isset($options['publish']) && $options['publish'])
        {
            MMSynchContentPublisher::getInstance()->publish($content);
        }

        return $content;
    }
Ejemplo n.º 11
0
 /**
  * Adds a new location to the location set
  * @param SQLILocation $location
  */
 public function addLocation(SQLILocation $location)
 {
     $this->locations[$location->attribute('node_id')] = $location;
     $this->initIterator();
 }