Exemplo n.º 1
0
 /**
  * Return last revision of this file
  *
  * @param void
  * @return ProjectFileRevision
  */
 function getLastRevision()
 {
     if (is_null($this->last_revision)) {
         $this->last_revision = ProjectFileRevisions::findOne(array('conditions' => array('`file_id` = ?', $this->getId()), 'order' => '`created_on` DESC', 'limit' => 1));
         // findOne
     }
     // if
     return $this->last_revision;
 }
 /**
  * This function will return paginated result. Result is an array where first element is 
  * array of returned object and second populated pagination object that can be used for 
  * obtaining and rendering pagination data using various helpers.
  * 
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'ProjectFileRevisions')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return ProjectFileRevisions::instance()->paginate($arguments, $items_per_page, $current_page);
         //$instance =& ProjectFileRevisions::instance();
         //return $instance->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }
 /**
  * Empty implementation of abstract methods. Messages determine does user have
  * permissions to add comment
  *
  * @param void
  * @return null
  */
 function canAdd(User $user, Project $project)
 {
     return can_add($user, $project, get_class(ProjectFileRevisions::instance()));
 }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return ProjectFileRevisions 
  */
 function manager()
 {
     if (!$this->manager instanceof ProjectFileRevisions) {
         $this->manager = ProjectFileRevisions::instance();
     }
     return $this->manager;
 }
Exemplo n.º 5
0
 /**
  * Delete selected revision (if you have proper permissions)
  *
  * @param void
  * @return null
  */
 function delete_revision()
 {
     $this->setTemplate('del_revision');
     $revision = ProjectFileRevisions::findById(get_id());
     if (!$revision instanceof ProjectFileRevision) {
         flash_error(lang('file revision dnx'));
         $this->redirectToReferer(get_url('files'));
     }
     // if
     $file = $revision->getFile();
     if (!$file instanceof ProjectFile) {
         flash_error(lang('file dnx'));
         $this->redirectToReferer(get_url('files'));
     }
     // if
     $all_revisions = $file->getRevisions();
     if (count($all_revisions) == 1) {
         flash_error(lang('cant delete only revision'));
         $this->redirectToReferer($file->getDetailsUrl());
     }
     // if
     if (!$revision->canDelete(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('files'));
     }
     // if
     $delete_data = array_var($_POST, 'deleteFileRevision');
     tpl_assign('file', $file);
     tpl_assign('revision', $revision);
     tpl_assign('delete_data', $delete_data);
     if (!is_array($delete_data)) {
         $delete_data = array('really' => 0, 'password' => '');
         // array
         tpl_assign('delete_data', $delete_data);
     } else {
         if ($delete_data['really'] == 1) {
             $password = $delete_data['password'];
             if (trim($password) == '') {
                 tpl_assign('error', new Error(lang('password value missing')));
                 return $this->render();
             }
             if (!logged_user()->isValidPassword($password)) {
                 tpl_assign('error', new Error(lang('invalid login data')));
                 return $this->render();
             }
             try {
                 DB::beginWork();
                 $revision->delete();
                 ApplicationLogs::createLog($revision, $revision->getProject(), ApplicationLogs::ACTION_DELETE);
                 DB::commit();
                 flash_success(lang('success delete file revision'));
             } catch (Exception $e) {
                 DB::rollback();
                 flash_error(lang('error delete file revision'));
             }
             // try
             $this->redirectToUrl($file->getDetailsUrl());
         } else {
             flash_error(lang('error delete file revision'));
             $this->redirectToUrl($file->getDetailsUrl());
         }
     }
 }
Exemplo n.º 6
0
	/**
	 * Delete selected revision (if you have proper permissions)
	 *
	 * @param void
	 * @return null
	 */
	function delete_file_revision() {
		if (logged_user()->isGuest()) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		}
		$revision = ProjectFileRevisions::findById(get_id());
		if(!($revision instanceof ProjectFileRevision)) {
			flash_error(lang('file revision dnx'));
			ajx_current("empty");
			return;
		} // if
			
		$file = $revision->getFile();
		if(!($file instanceof ProjectFile)) {
			flash_error(lang('file dnx'));
			ajx_current("empty");
			return;
		} // if
			
		$all_revisions = $file->getRevisions();
		if(count($all_revisions) == 1) {
			flash_error(lang('cant delete only revision'));
			ajx_current("empty");
			return;
		} // if
			
		if(!$file->canDelete(logged_user())) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		} // if
			
		try {
			DB::beginWork();
			$revision->trash();
			
			ApplicationLogs::createLog($revision, ApplicationLogs::ACTION_TRASH);
			DB::commit();

			flash_success(lang('success trash file revision'));
			ajx_current("reload");
		} catch(Exception $e) {
			DB::rollback();
			flash_error(lang('error trash object'));
			ajx_current("empty");
		} // try
	} // delete_file_revision
 function findByFile($file_id)
 {
     return ProjectFileRevisions::findOne(array('conditions' => array('`file_id` = ?', $file_id)));
 }
 function addToSearchableObjects($wasNew = false)
 {
     $columns_to_drop = array();
     if ($wasNew) {
         $columns_to_drop = $this->getSearchableColumns();
     } else {
         $searchable_columns = $this->getSearchableColumns();
         if (is_array($searchable_columns)) {
             foreach ($searchable_columns as $column_name) {
                 if (isset($this->searchable_composite_columns[$column_name])) {
                     foreach ($this->searchable_composite_columns[$column_name] as $colName) {
                         if ($this->isColumnModified($colName)) {
                             $columns_to_drop[] = $column_name;
                             break;
                         }
                     }
                 } else {
                     if ($this->isColumnModified($column_name)) {
                         $columns_to_drop[] = $column_name;
                     }
                 }
             }
         }
         $searchable_columns = null;
     }
     if (count($columns_to_drop) > 0) {
         if (!$wasNew) {
             SearchableObjects::dropContentByObjectColumns($this, $columns_to_drop);
         }
         $docx_id = FileTypes::findOne(array('id' => true, 'conditions' => '`extension` = ' . DB::escape('docx')));
         $pdf_id = FileTypes::findOne(array('id' => true, 'conditions' => '`extension` = ' . DB::escape('pdf')));
         $odt_id = FileTypes::findOne(array('id' => true, 'conditions' => '`extension` = ' . DB::escape('odt')));
         $fodt_id = FileTypes::findOne(array('id' => true, 'conditions' => '`extension` = ' . DB::escape('fodt')));
         foreach ($columns_to_drop as $column_name) {
             $content = $this->getSearchableColumnContent($column_name);
             if (get_class($this->manager()) == 'ProjectFiles') {
                 $content = utf8_encode($content);
             } elseif (get_class($this->manager()) == 'ProjectFileRevisions') {
                 if ($column_name == "filecontent") {
                     $file = ProjectFileRevisions::findById($this->getObjectId());
                     try {
                         if ($file->getFileTypeId() == $docx_id) {
                             if (class_exists('DOMDocument')) {
                                 $file_path = "tmp/doc_filecontent_" . $this->getObjectId() . ".docx";
                                 $file_tmp = @fopen($file_path, 'w');
                                 if ($file_tmp) {
                                     fwrite($file_tmp, $file->getFileContent());
                                     fclose($file_tmp);
                                     $content = docx2text($file_path);
                                     unlink($file_path);
                                 }
                             }
                         } elseif ($file->getFileTypeId() == $pdf_id) {
                             $file_path = "tmp/pdf_filecontent_" . $this->getObjectId() . ".pdf";
                             $file_tmp = @fopen($file_path, 'w');
                             if ($file_tmp) {
                                 fwrite($file_tmp, $file->getFileContent());
                                 fclose($file_tmp);
                                 $content = pdf2text($file_path);
                                 unlink($file_path);
                             }
                         } elseif ($file->getFileTypeId() == $odt_id) {
                             if (class_exists('DOMDocument')) {
                                 $file_path = "tmp/odt_filecontent_" . $this->getObjectId() . ".odt";
                                 $file_tmp = @fopen($file_path, 'w');
                                 if ($file_tmp) {
                                     fwrite($file_tmp, $file->getFileContent());
                                     fclose($file_tmp);
                                     $content = odt2text($file_path);
                                     unlink($file_path);
                                 }
                             }
                         } elseif ($file->getFileTypeId() == $fodt_id) {
                             $file_path = "tmp/fodt_filecontent_" . $this->getObjectId() . ".fodt";
                             $file_tmp = @fopen($file_path, 'w');
                             if ($file_tmp) {
                                 fwrite($file_tmp, $file->getFileContent());
                                 fclose($file_tmp);
                                 $content = fodt2text($file_path, $this->getObjectId());
                                 unlink($file_path);
                             }
                         }
                     } catch (FileNotInRepositoryError $e) {
                         $content = "";
                     }
                 } else {
                     $content = utf8_encode($content);
                 }
             }
             if (trim($content) != '') {
                 $searchable_object = new SearchableObject();
                 $searchable_object->setRelObjectId($this->getObjectId());
                 $searchable_object->setColumnName(DB::escape($column_name));
                 if (strlen($content) > 65535) {
                     $content = utf8_safe(substr($content, 0, 65535));
                 }
                 $content = DB::escape($content);
                 $sql = "\n\t\t\t\t\t\tINSERT INTO " . TABLE_PREFIX . "searchable_objects (rel_object_id, column_name, content)\n\t\t\t\t\t\tVALUES (" . $searchable_object->getRelObjectId() . "," . $searchable_object->getColumnName() . "," . $content . ")\n\t\t\t\t\t\tON DUPLICATE KEY UPDATE content = {$content}";
                 DB::execute($sql);
                 $searchable_object = null;
             }
             $content = null;
         }
     }
     $columns_to_drop = null;
 }
 function getViewUrl() {
 	if (!$this->isLoaded()){
 		$fileRevision = ProjectFileRevisions::instance()->findById($this->getId(), 1);
 		$file = $fileRevision->getFile();
 	}else{
 		$file = $this->getFile();
 	}
 	
 	if ( $file ) {
 		return $file->getViewUrl();
 	}else{
 		return "#";
 	}
 }
 /**
 * Return manager instance
 *
 * @access protected
 * @param void
 * @return ProjectFileRevisions 
 */
 function manager() {
   if(!($this->manager instanceof ProjectFileRevisions)) $this->manager = ProjectFileRevisions::instance();
   return $this->manager;
 } // manager