/** * Edit existing file information * * @param void * @return null */ function edit() { $this->wireframe->print_button = false; if ($this->request->isApiCall() && !$this->request->isSubmitted()) { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if if ($this->active_file->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_file->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $file_data = $this->request->post('file'); if (!is_array($file_data)) { $file_data = array('name' => $this->active_file->getName(), 'body' => $this->active_file->getBody(), 'visibility' => $this->active_file->getVisibility(), 'parent_id' => $this->active_file->getParentId(), 'milestone_id' => $this->active_file->getMilestoneId(), 'tags' => $this->active_file->getTags()); } // if $this->smarty->assign('file_data', $file_data); if ($this->request->isSubmitted()) { db_begin_work(); $old_name = $this->active_file->getName(); $this->active_file->setAttributes($file_data); $save = $this->active_file->save(); if ($save && !is_error($save)) { db_commit(); //BOF: mod $this->active_file->register_departments(!empty($file_data['departments']) ? $file_data['departments'] : array()); //EOF: mod if ($this->request->isApiCall()) { $this->serveData($this->active_file, 'file'); } else { flash_success('File ":name" has been updated', array('name' => $old_name)); $this->redirectToUrl($this->active_file->getViewUrl()); } // if } else { db_rollback(); if ($this->request->isApiCall()) { $this->serveData($save); } else { $this->smarty->assign('errors', $save); } // if } // if } // if }