예제 #1
0
 public static function createSource($id_user)
 {
     $table = new Sources();
     $id = $table->addSource($id_user, $this->_prefix);
     $source = $this->__construct($id);
     return $source;
 }
예제 #2
0
 public static function forUser($id)
 {
     $properties = new Properties(array(Properties::KEY => $id));
     $sources = new Sources(array(Stuffpress_Db_Table::USER => $id));
     $source_id = $properties->getProperty('stuffpress_source');
     if (!$source_id) {
         $source_id = $sources->addSource('stuffpress');
         $sources->setImported($source_id, 1);
         $properties->setProperty('stuffpress_source', $source_id);
     }
     $source = $sources->getSource($source_id);
     return new StuffpressModel($source);
 }
예제 #3
0
 public function saveAction()
 {
     // We need the Sources database in this function
     $sources = new Sources();
     // Get the source from the request
     $id = $this->_getParam('id');
     $service = $this->_getParam('service');
     // Instantiate a model for the source
     $model = SourceModel::newInstance($service);
     // Build the form and validate
     $form = $this->buildform($model);
     if (!$form->isValid($_POST)) {
         // Failed validation; redisplay form
         $this->view->failedValidation = true;
         $this->view->service_name = $model->getServiceName();
         $this->view->form = $form;
         return $this->render('edit');
     }
     // If we don't have a source, it means we create something
     $create = $id > 0 ? false : true;
     if ($create) {
         $id = $sources->addSource($service);
     }
     // Check if the source exist
     if (!($source = $sources->getSource($id))) {
         throw new Stuffpress_Exception("Unknown source with id {$id}");
     }
     // Check if we are the owner of the source
     if ($source['user_id'] != $this->_application->user->id) {
         throw new Stuffpress_AccessDeniedException("Not the owner of source {$id}");
     }
     // Assign the source to the model
     $model->setSource($source);
     // Get the values, and update the settings
     $update = $model->processConfigForm($form);
     // Import the data NOW if a new source
     if ($update) {
         try {
             $model->setImported(0);
             $count = count($model->importData());
         } catch (Exception $e) {
             $count = 0;
             $error = $e->getMessage();
             Zend_Registry::get('logger')->log("Exception updating {$service} ({$id}): " . $e->getMessage(), Zend_Log::ERR);
         }
         if ($count) {
             $this->addStatusMessage("Successfully imported {$count} entries.");
         } else {
             if (isset($error)) {
                 $this->addErrorMessage("There was an error while importing the data. Please doublecheck your import configuration and try again later. Let us know if this problem persists.");
                 if ($create) {
                     $sources->deleteSource($id);
                 }
             } else {
                 $this->addStatusMessage("No data imported. Maybe there is nothing available at the moment. Please double-check your import configuration just in case.");
             }
         }
     } else {
         $this->addStatusMessage("Settings saved.");
     }
     // Add a succes message and forward to the index
     return $this->_forward('index', 'services', 'admin');
 }