Ejemplo n.º 1
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
Ejemplo n.º 2
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());
         }
     }
 }
 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;
 }