/** * View the file * */ function view() { if ($this->active_file->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_file->canView($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $last_revision = $this->active_file->getLastRevision(); if (!instance_of($last_revision, 'Attachment')) { flash_error('Invalid file - last revision was not found'); $this->redirectToUrl(assemble_url('mobile_access')); } // if ProjectObjectViews::log($this->active_file, $this->logged_user); ProjectObjectViews::log($last_revision, $this->logged_user); $this->smarty->assign(array('revisions' => $this->active_file->getRevisions(), 'last_revision' => $last_revision, 'page_back_url' => assemble_url('mobile_access_view_files', array('project_id' => $this->active_project->getId())))); $this->addBreadcrumb(str_excerpt(clean($this->active_file->getName()), 10), mobile_access_module_get_view_url($this->active_file)); $this->addBreadcrumb(lang('View')); }
/** * Upload new file version * * @param void * @return null */ function new_version() { 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 if ($this->request->isSubmitted()) { $attached = attach_from_files($this->active_file, $this->logged_user); if ($attached && !is_error($attached)) { $this->active_file->setRevision($this->active_file->getRevision() + 1); $save = $this->active_file->save(); if ($save && !is_error($save)) { $last_revision = $this->active_file->getLastRevision(); if (instance_of($last_revision, 'Attachment')) { $last_revision->setCreatedBy($this->logged_user); $last_revision->setAttachmentType(ATTACHMENT_TYPE_FILE_REVISION); $last_revision->save(); event_trigger('on_new_revision', array(&$this->active_file, &$last_revision, &$this->logged_user)); $activity_log = new NewFileVersionActivityLog(); $activity_log->log($this->active_file, $this->logged_user, $last_revision->getId()); } // if Subscriptions::subscribe($this->logged_user, $this->active_file); db_commit(); flash_success('File ":name" has been updated', array('name' => $this->active_file->getName())); $this->redirectToUrl($this->active_file->getViewUrl()); } else { db_rollback(); $this->smarty->assign('errors', $save); } // if } else { if (is_error($attached)) { $errors = new ValidationErrors(array('file' => $attached->getMessage())); } else { $errors = new ValidationErrors(array('file' => lang('File not uploaded'))); } // if $this->smarty->assign('errors', $errors); } // if } // if }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->asfGuardUser !== null) { if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) { $affectedRows += $this->asfGuardUser->save($con); } $this->setsfGuardUser($this->asfGuardUser); } if ($this->aRepository !== null) { if ($this->aRepository->isModified() || $this->aRepository->isNew()) { $affectedRows += $this->aRepository->save($con); } $this->setRepository($this->aRepository); } if ($this->aBranch !== null) { if ($this->aBranch->isModified() || $this->aBranch->isNew()) { $affectedRows += $this->aBranch->save($con); } $this->setBranch($this->aBranch); } if ($this->aFile !== null) { if ($this->aFile->isModified() || $this->aFile->isNew()) { $affectedRows += $this->aFile->save($con); } $this->setFile($this->aFile); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aFeaturevector !== null) { if ($this->aFeaturevector->isModified() || $this->aFeaturevector->isNew()) { $affectedRows += $this->aFeaturevector->save($con); } $this->setFeaturevector($this->aFeaturevector); } if ($this->aFile !== null) { if ($this->aFile->isModified() || $this->aFile->isNew()) { $affectedRows += $this->aFile->save($con); } $this->setFile($this->aFile); } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = FeaturevectorsegmentPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setNew(false); } else { $affectedRows += FeaturevectorsegmentPeer::doUpdate($this, $con); } // Rewind the data LOB column, since PDO does not rewind after inserting value. if ($this->data !== null && is_resource($this->data)) { rewind($this->data); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }