예제 #1
0
 /**
  * Add a new file.
  *
  */
 public function uploadAction()
 {
     if (!$this->_getParam('updated')) {
         $this->_setParam('updated', date('Y-m-d H:i:s'));
     }
     $model = null;
     $parent = '';
     try {
         $params = $this->filterParams($this->_getAllParams());
         $doUpload = false;
         if (isset($_FILES['file']) && strlen(ifset($_FILES['file'], 'tmp_name', ''))) {
             $doUpload = true;
         }
         $filename = ifset($this->_getAllParams(), 'filename');
         if (!strlen($filename) && $doUpload) {
             $filename = $_FILES['file']['name'];
         }
         $parent = trim(base64_decode($this->_getParam('parent')), " /");
         $id = $this->_getParam('id');
         if ($id) {
             // updating
             $file = $this->fileService->getFile($id);
         } else {
             if ($doUpload == false) {
                 // if we're not doing an upload, but the file doesn't
                 // exist yet, lets bail
                 throw new Exception("You must upload a file");
             }
             $file = $this->fileService->createFile($filename, $parent);
         }
         if ($doUpload) {
             $this->fileService->setFile($file, $_FILES['file']['tmp_name']);
         }
         $params = $this->_getAllParams();
         $params['filename'] = $filename;
         if (!empty($parent)) {
             $params['path'] = $parent;
         }
         $file->bind($params);
         $this->fileService->saveFile($file);
         $this->cacheService->expire($parent);
     } catch (InvalidModelException $ime) {
         $this->flash("Invalid model: " . $ime->getMessages());
         $model = new File();
         $model->bind($this->_getAllParams());
         $this->editAction($model);
         return;
     } catch (Exception $e) {
         $this->flash(get_class($e) . ': ' . $e->getMessage());
         error_log(get_class($e) . ': ' . $e->getMessage());
         error_log($e->getTraceAsString());
         $model = new File();
         $model->bind($this->_getAllParams());
         $this->editAction($model);
         return;
     }
     $picker = $this->_getParam('picker');
     $returnUrl = $this->_getParam('returnurl');
     if (!empty($returnUrl)) {
         $this->redirect(base64_decode($this->_getParam('returnurl')), '', array('picker' => $picker));
     } else {
         $this->redirect('file', 'index', array('picker' => $picker, 'parent' => base64_encode($parent)));
     }
 }
예제 #2
0
 /**
  * Save a project
  *
  * @param array|Project $params
  */
 public function saveProject($params)
 {
     $this->dbService->beginTransaction();
     // Double check to see whether the children projects are actually
     // a parent of the selected parent
     $pid = 0;
     $parent = 0;
     $project = null;
     $clientid = 0;
     if (is_array($params)) {
         $pid = ifset($params, 'id');
         $parent = ifset($params, 'parentid');
         if ($pid) {
             $project = $this->getProject($pid);
             $clientid = ifset($params, 'clientid', $project->clientid);
         }
     } else {
         $pid = $params->id;
         $parent = $params->parentid;
         $project = $params;
         $clientid = $project->clientid;
     }
     if ($pid) {
         // check the current parent client, if it's changed we need to update all our
         // child projects as well to let them know that the parent is now different
         $proj = $this->dbService->getById($pid, 'Project');
         $updateChildren = false;
         if ($proj->clientid != $clientid) {
             // update all the children too
             $updateChildren = true;
         }
         // get all the children (including grandchildren and milestones)
         /* @var $project Project */
         $children = $project->getContainedMilestones();
         // see if the selected parent is in the list of children at all
         foreach ($children as $childProject) {
             if ($childProject->id == $parent) {
                 throw new Exception("Cannot create recursive project hierarchy");
             }
             $this->log->debug("Updating project " . $childProject->title . " to client {$clientid}");
             if ($updateChildren) {
                 $childProject->clientid = $clientid;
                 $this->dbService->saveObject($childProject, 'Project');
             }
         }
     } else {
         // we're creating a new project, so lets update the cache list
         $this->cacheService->expire($this->clientProjectsCacheKey($clientid));
     }
     if ($params instanceof Project) {
         $this->updateProjectEstimate($params);
     }
     $savedProject = $this->dbService->saveObject($params, 'Project');
     // If this project's due date is greater than the parent's due date,
     // then update that parent's due date
     if ($savedProject && $savedProject->parentid) {
         $parentProject = $this->dbService->getById($savedProject->parentid, 'Project');
         $parentEnd = strtotime($parentProject->due);
         $thisEnd = strtotime($savedProject->due);
         if ($thisEnd > $parentEnd) {
             $parentProject->due = $savedProject->due;
             $this->saveProject($parentProject);
             $group = $this->groupService->getGroup($parentProject->ownerid);
             // Only send if the group exists
             if ($group) {
                 $users = $this->groupService->getUsersInGroup($group);
                 $msg = new TemplatedMessage('project-end-updated.php', array('model' => $parentProject));
                 try {
                     $this->notificationService->notifyUser("Project due date changed", $users, $msg);
                 } catch (Exception $e) {
                     $this->log->warn("Failed sending project update email");
                 }
             }
         }
         if (mb_strlen($savedProject->actualstart) && !mb_strlen($parentProject->actualstart)) {
             $parentProject->actualstart = $savedProject->actualstart;
             $this->saveProject($parentProject);
         }
     }
     $this->dbService->commit();
     return $savedProject;
 }