/**
  * Starts the actual pending export.
  *
  * @throws PlentymarketsExportException
  */
 public function export()
 {
     if ($this->isRunning == true) {
         throw new PlentymarketsExportException('Another export is running at this very moment', 2510);
     }
     // Check whether settings and mapping is complete
     if ($this->mayRun == false) {
         throw new PlentymarketsExportException('Either the mapping or the settings is not finished or the data integrity is not valid', 2520);
     }
     // Get the pending entity
     $entity = $this->Config->getExportEntityPending(false);
     // No exception.. or the log will ne spammed
     if ($entity == false) {
         return;
     }
     // Set the running flag and delete the last call timestmap and the pending entity
     $this->Config->setIsExportRunning(1);
     $this->Config->eraseExportEntityPending();
     $this->Config->eraseInitialExportLastCallTimestamp();
     // Configure the SOAP client to log the timestamp of the calls from now on
     PlentymarketsSoapClient::getInstance()->setTimestampConfigKey('InitialExportLastCallTimestamp');
     // Log the start
     PlentymarketsLogger::getInstance()->message('Export:Initial:' . $entity, 'Starting');
     // Get the entity status object
     $Status = $this->StatusController->getEntity($entity);
     // Set running
     $Status->setStatus(PlentymarketsExportStatus::STATUS_RUNNING);
     // Set the start timestamp if that hasn't already been done
     if ((int) $Status->getStart() <= 0) {
         $Status->setStart(time());
     }
     try {
         // Get the controller
         $class = sprintf('PlentymarketsExportController%s', $entity);
         // and run it
         $Instance = new $class();
         $Instance->run();
         // Log that we are done
         PlentymarketsLogger::getInstance()->message('Export:Initial:' . $entity, 'Done!');
         // If the export is finished
         if ($Instance->isFinished()) {
             // set the success status and the finished timestamp
             $Status->setStatus(PlentymarketsExportStatus::STATUS_SUCCESS);
             $Status->setFinished(time());
         } else {
             // otherwise re-announce the entity for the next run
             $this->Config->setExportEntityPending($Status->getName());
             $Status->setStatus(PlentymarketsExportStatus::STATUS_PENDING);
         }
     } catch (PlentymarketsExportException $E) {
         // Log and save the error
         PlentymarketsLogger::getInstance()->error('Export:Initial:' . $entity, $E->getMessage(), $E->getCode());
         $Status->setError($E->getMessage());
     }
     // Reconfigure the soap client
     PlentymarketsSoapClient::getInstance()->setTimestampConfigKey(null);
     // Erase the timestamp of the latest export call
     $this->Config->eraseInitialExportLastCallTimestamp();
     // Reset the running flag
     $this->Config->setIsExportRunning(0);
 }