Example #1
0
 /**
  * One and only phase, content synchronisation.
  */
 public function syncAllContent()
 {
     yamm_api_debug("Transaction " . $this->_tid . " running");
     try {
         // FIXME: This is hardcoded right now, but it will change.
         $fetcher = new Yamm_EntityFetcher_Xmlrpc($this->_tid);
         $fetcher->setServer($this->_server);
         $fileFetcher = new Yamm_FileFetcher_Http($this->_server);
         $this->_entityParser = new Yamm_EntityParser($fetcher, $fileFetcher);
         $this->_entityParser->parse();
         module_invoke_all('yamm_sync_finished');
         $this->sendStatus(YAMM_TRANSACTION_STATUS_FINISHED);
         return TRUE;
     } catch (Yamm_EntityFetcherException $e) {
         yamm_api_debug($e->getMessage());
         yamm_api_debug($e->getTraceAsString());
         // If we dont change status here, no other transanctions this client wont
         // be able to run any more transaction.
         $this->cancel();
     } catch (Yamm_EntityException $e) {
         yamm_api_debug($e->getMessage());
         yamm_api_debug($e->getTraceAsString());
         // If we dont change status here, no other transanctions this client wont
         // be able to run any more transaction.
         $this->fail();
     }
     return FALSE;
 }
Example #2
0
 /**
  * Save object on local Drupal. This should be only call within the
  * Yamm_EntityParser implementation.
  */
 public function save()
 {
     $this->__hookPresave();
     // Update object
     try {
         $this->__identifier = Yamm_EntityFactory::getIdentifierByUuid($this->__uuid);
         // Check object has not been deleted on client
         if (!$this->_objectExists()) {
             throw new Yamm_Entity_DeletedOnClientException("Object has been deleted");
         }
         $this->_update($this->__object, $this->__identifier);
         yamm_api_debug('Update @entity', array('@entity' => $this));
         $this->__hookUpdate();
     } catch (Yamm_Entity_DeletedOnClientException $e) {
         yamm_api_uuid_delete($this->__uuid);
         $this->__identifier = $this->_save($this->__object);
         if (!$this->__identifier) {
             yamm_api_debug('Insert after deletion failed for @entity', array('@entity' => $this));
             throw new Yamm_Entity_UnableToSaveObjectException("Object could not be saved (after deletion)");
         }
         yamm_api_uuid_save($this->__uuid, $this->_type, $this->__identifier);
         yamm_api_debug('Insert after deletion for @entity', array('@entity' => $this));
         $this->__hookSave();
     } catch (Yamm_Entity_UnknownUuidException $e) {
         $this->__identifier = $this->_save($this->__object);
         if (!$this->__identifier) {
             yamm_api_debug('Insert failed for @entity', array('@entity' => $this));
             throw new Yamm_Entity_UnableToSaveObjectException("Object could not be saved");
         }
         yamm_api_uuid_save($this->__uuid, $this->_type, $this->__identifier);
         yamm_api_debug('Insert @entity', array('@entity' => $this));
         $this->__hookSave();
     }
 }
Example #3
0
 /**
  * (non-PHPdoc)
  * @see Yamm_FileFetcherInterface::fetchDrupalFile()
  */
 public function fetchDrupalFile($file, $dest = 0, $replace = FALSE)
 {
     // Fetch the real file as a temporary file.
     $src = $this->_fetch($file->filepath);
     // Create the new file destination. Use the $replace boolean to compute a
     // new file name if the the user asked for no file replace.
     $dest = file_destination(file_create_path($dest) . '/' . $file->filename, $replace ? FILE_EXISTS_REPLACE : FILE_EXISTS_RENAME);
     yamm_api_debug("Copying file " . $src . " to " . $dest);
     // Copy the temporary file as the real file.
     $error = !copy($src, $dest);
     // In all case, remove the temporary file. Be silent here, whatever happens.
     // In case of unlink failure, only put a warning message in watchdog.
     if (!unlink($src)) {
         watchdog('yamm', "Temporary file " . $src . " could not be deleted", NULL, WATCHDOG_WARNING);
     }
     // Treat error after having the file removed.
     if ($error) {
         yamm_api_debug("Error while copying file " . $src . " to " . $dest);
         throw new Yamm_FileFetcher_CouldNotSaveException("File " . $src . " could not copied to " . $dest);
     }
     // Set the new filepath to our file structure.
     $file->filepath = $dest;
 }
Example #4
0
 /**
  * Build a full tree of dependencies.
  *
  * @param Yamm_Entity $entity
  *   Entity for which to fetch dependencies.
  */
 protected function _buildDependencies(Yamm_Entity $entity)
 {
     $dependencies = $entity->getDependencies();
     $this->_pruneDependencies($dependencies);
     yamm_api_debug("Entity parser got @count dependencies", array('@count' => count($dependencies)));
     // Go and unpack them.
     foreach ($this->_fetcher->fetchDependencies($dependencies) as $depEntity) {
         // Check for already builded ones (circular dependencies).
         if (!$this->_alreadyBuilt($depEntity)) {
             // And build it.
             $this->_buildDependencies($depEntity);
         }
     }
     $entity->save();
 }