Beispiel #1
0
 /**
  * Save a record
  *
  * @return  void
  */
 public function saveTask()
 {
     // check token
     Request::checkToken();
     // get request vars
     $fields = Request::getVar('hook', array(), 'post');
     $file = Request::getVar('file', array(), 'FILES');
     // Create hook model object
     $hook = Hook::blank()->set($fields);
     $hook->set('type', 'members');
     // Is this a new import?
     $isNew = false;
     if ($hook->isNew()) {
         $isNew = true;
         // set the created by/at
         $hook->set('created_by', User::get('id'));
         $hook->set('created', Date::toSql());
     }
     // Attempt to save
     if (!$hook->save()) {
         $this->setError($hook->getError());
         return $this->editTask();
     }
     // Is this a new record?
     if ($isNew) {
         // Create folder for files
         $this->_createImportFilespace($hook);
     }
     // If we have a file
     if ($file['size'] > 0 && $file['error'] == 0) {
         move_uploaded_file($file['tmp_name'], $hook->fileSpacePath() . DS . $file['name']);
         $hook->set('file', $file['name']);
         $hook->save();
     }
     Notify::success(Lang::txt('COM_MEMBERS_IMPORTHOOK_CREATED'));
     // Inform user & redirect
     if ($this->getTask() == 'apply') {
         return $this->editTask($hook);
     }
     $this->cancelTask();
 }