コード例 #1
0
	/**
	 * Create new log entry and return it
	 *
	 * Delete actions are automatically marked as silent if $is_silent value is not provided (not NULL)
	 *
	 * @param ApplicationDataObject $object
	 * @param Project $project
	 * @param DataManager $manager
	 * @param boolean $save Save log object before you save it
	 * @return ApplicationLog
	 */
	static function createLog($object, $action = null, $is_private = false, $is_silent = null, $save = true, $log_data = '') {
		if(is_null($action)) {
			$action = self::ACTION_ADD;
		} // if
		if(!self::isValidAction($action)) {
			throw new Error("'$action' is not valid log action");
		} // if

		if(is_null($is_silent)) {
			$is_silent = $action == self::ACTION_DELETE;
		} else {
			$is_silent = (boolean) $is_silent;
		} // if

		if (!$is_silent) {
			try {
				Notifier::notifyAction($object, $action, $log_data);
			} catch (Exception $ex) {
				Logger::log($ex->getMessage());
			}
		}
		
		$log = new ApplicationLog();
		if (logged_user() instanceof Contact) {
			$log->setTakenById(logged_user()->getId());
		} else {
			$log->setTakenById(0);
		}
		if ($object instanceof ContentDataObject) {
			$log->setRelObjectId($object->getObjectId());
			$log->setObjectName($object->getObjectName());
		}
		if ($object instanceof Member) {
			$log->setRelObjectId($object->getId());
			$log->setObjectName($object->getName());
		}
		
		$log->setAction($action);
		$log->setIsPrivate($is_private);
		$log->setIsSilent($is_silent);
		$log->setLogData($log_data);
		
		if($save) {
			$log->save();
		} // if
		
		return $log;
	} // createLog
コード例 #2
0
 /**
  * Create new log entry and return it
  * 
  * Delete actions are automaticly marked as silent if $is_silent value is not provided (not NULL)
  *
  * @param ApplicationDataObject $object
  * @param Project $project
  * @param DataManager $manager
  * @param boolean $save Save log object before you save it
  * @return ApplicationLog
  */
 static function createLog(ApplicationDataObject $object, $project, $action = null, $is_private = false, $is_silent = null, $save = true)
 {
     if (is_null($action)) {
         $action = self::ACTION_ADD;
     }
     // if
     if (!self::isValidAction($action)) {
         throw new Error("'{$action}' is not valid log action");
     }
     // if
     if (is_null($is_silent)) {
         $is_silent = $action == self::ACTION_DELETE;
     } else {
         $is_silent = (bool) $is_silent;
     }
     // if
     $manager = $object->manager();
     if (!$manager instanceof DataManager) {
         throw new Error('Invalid object manager');
     }
     // if
     $log = new ApplicationLog();
     if ($project instanceof Project) {
         $log->setProjectId($project->getId());
     }
     // if
     $log->setTakenById(logged_user()->getId());
     $log->setRelObjectId($object->getObjectId());
     $log->setObjectName($object->getObjectName());
     $log->setRelObjectManager(get_class($manager));
     $log->setAction($action);
     $log->setIsPrivate($is_private);
     $log->setIsSilent($is_silent);
     if ($save) {
         $log->save();
     }
     // if
     // Update is private for this object
     if ($object instanceof ProjectDataObject) {
         ApplicationLogs::setIsPrivateForObject($object);
     }
     // if
     return $log;
 }
コード例 #3
0
 /**
  * Create new log entry and return it
  *
  * Delete actions are automatically marked as silent if $is_silent value is not provided (not NULL)
  *
  * @param ApplicationDataObject $object
  * @param Project $project
  * @param DataManager $manager
  * @param boolean $save Save log object before you save it
  * @return ApplicationLog
  */
 static function createLog(ApplicationDataObject $object, $workspaces, $action = null, $is_private = false, $is_silent = null, $save = true, $log_data = '')
 {
     if (is_null($action)) {
         $action = self::ACTION_ADD;
     }
     // if
     if (!self::isValidAction($action)) {
         throw new Error("'{$action}' is not valid log action");
     }
     // if
     if (is_null($is_silent)) {
         $is_silent = $action == self::ACTION_DELETE;
     } else {
         $is_silent = (bool) $is_silent;
     }
     // if
     if (!$is_silent) {
         try {
             Notifier::notifyAction($object, $action, $log_data);
         } catch (Exception $ex) {
         }
     }
     if ($object != null) {
         $manager = $object->manager();
     }
     if (!$manager instanceof DataManager) {
         throw new Error('Invalid object manager');
     }
     // if
     $log = new ApplicationLog();
     if (logged_user() instanceof User) {
         $log->setTakenById(logged_user()->getId());
     } else {
         $log->setTakenById(0);
     }
     $log->setRelObjectId($object->getObjectId());
     $log->setObjectName($object->getObjectName());
     $log->setRelObjectManager(get_class($manager));
     $log->setAction($action);
     $log->setIsPrivate($is_private);
     $log->setIsSilent($is_silent);
     $log->setLogData($log_data);
     if ($save) {
         $log->save();
     }
     // if
     // Update is private for this object
     /*if($object instanceof ProjectDataObject) {
     			ApplicationLogs::setIsPrivateForObject($object);
     		} // if*/
     if ($save) {
         if ($workspaces instanceof Project) {
             $wo = new WorkspaceObject();
             $wo->setObject($log);
             $wo->setWorkspace($workspaces);
             $wo->save();
         } else {
             if (is_array($workspaces)) {
                 foreach ($workspaces as $w) {
                     if ($w instanceof Project) {
                         $wo = new WorkspaceObject();
                         $wo->setObject($log);
                         $wo->setWorkspace($w);
                         $wo->save();
                     }
                 }
             }
         }
     }
     return $log;
 }
コード例 #4
0
 /**
  * Create new log entry and return it
  *
  * Delete actions are automatically marked as silent if $is_silent value is not provided (not NULL)
  *
  * @param ApplicationDataObject $object
  * @param Project $project
  * @param DataManager $manager
  * @param boolean $save Save log object before you save it
  * @return ApplicationLog
  */
 static function createLog($object, $action = null, $is_private = false, $is_silent = null, $save = true, $log_data = '')
 {
     $args = array('action' => &$action, 'is_private' => &$is_private, 'is_silent' => &$is_silent, 'save' => &$save, 'log_data' => &$log_data);
     /**
      * Modify log and notification parameters before creating the application log registry
      */
     Hook::fire('application_logs_create', $object, $args);
     if (is_null($action)) {
         $action = self::ACTION_ADD;
     }
     // if
     if (!self::isValidAction($action)) {
         throw new Error("'{$action}' is not valid log action");
     }
     // if
     if ($object instanceof TemplateTask || $object instanceof TemplateMilestone) {
         $is_silent = true;
     }
     if (is_null($is_silent)) {
         $is_silent = $action == self::ACTION_DELETE;
     } else {
         $is_silent = (bool) $is_silent;
     }
     // if
     if (!$is_silent) {
         try {
             Notifier::notifyAction($object, $action, $log_data);
         } catch (Exception $ex) {
             Logger::log($ex->getMessage());
         }
     }
     $log = new ApplicationLog();
     if (logged_user() instanceof Contact) {
         $log->setTakenById(logged_user()->getId());
     } else {
         $log->setTakenById(0);
     }
     if ($object instanceof ContentDataObject) {
         $log->setRelObjectId($object->getObjectId());
         $log->setObjectName($object->getObjectName());
     }
     if ($object instanceof Member) {
         $log->setMemberId($object->getId());
         $log->setRelObjectId($object->getObjectId());
         $log->setObjectName($object->getName());
     }
     $log->setAction($action);
     $log->setIsPrivate($is_private);
     $log->setIsSilent($is_silent);
     $log->setLogData($log_data);
     if ($save) {
         $log->save();
     }
     // if
     return $log;
 }
コード例 #5
0
ファイル: Trash.class.php プロジェクト: abhinay100/feng_app
 function purge_trash($days = null, $limit = null, $extra_conditions = "")
 {
     ini_set('memory_limit', '512M');
     Env::useHelper("permissions");
     if (is_null($days)) {
         $days = config_option("days_on_trash");
     }
     if (is_null($limit)) {
         $limit = 1000;
     }
     $count = 0;
     if ($days >= 0) {
         $object_ids = array();
         $date = DateTimeValueLib::now()->add("d", -$days);
         $mail_join = "";
         $mail_cond = "";
         if (Plugins::instance()->isActivePlugin('mail')) {
             $mail_join = "LEFT JOIN " . TABLE_PREFIX . "mail_contents mc ON mc.object_id=o.id";
             $mail_cond = "AND NOT COALESCE(mc.is_deleted, false)";
         }
         $perm_join = "";
         $perm_conditions = "";
         if (logged_user() instanceof Contact) {
             $logged_user_pgids = logged_user()->getPermissionGroupIds();
             $perm_join = "INNER JOIN " . TABLE_PREFIX . "object_members om on om.object_id=o.id \r\n\t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "contact_member_permissions cmp ON cmp.member_id=om.member_id AND cmp.object_type_id=o.object_type_id";
             $perm_conditions = "AND cmp.can_delete=1 AND cmp.permission_group_id IN (" . implode(',', $logged_user_pgids) . ")";
         }
         $sql = "SELECT o.id as id, o.name as name, ot.name as ot_name, ot.table_name as table_name\r\n\t\t\t\t\tFROM " . TABLE_PREFIX . "objects o \r\n\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "object_types ot ON ot.id=o.object_type_id {$mail_join} {$perm_join}\r\n\t\t\t\t\tWHERE trashed_by_id > 0 AND trashed_on < '" . $date->toMySQL() . "' {$mail_cond} {$extra_conditions} {$perm_conditions}\r\n\t\t\t\t\tLIMIT {$limit}";
         $rows = DB::executeAll($sql);
         foreach ($rows as $row) {
             try {
                 DB::beginWork();
                 $id = $row['id'];
                 $ot_name = $row['ot_name'];
                 $name = $row['name'];
                 $table_name = $row['table_name'];
                 $object_ids[] = $id;
                 // delete object information
                 $tables_to_delete = self::get_tables_to_clean($ot_name);
                 if ($ot_name != 'mail' && $ot_name != 'invoice') {
                     $tables_to_delete[] = array('table' => TABLE_PREFIX . $table_name, 'column' => 'object_id');
                 }
                 foreach ($tables_to_delete as $table_info) {
                     $table = $table_info['table'];
                     $column = $table_info['column'];
                     $sql = "DELETE FROM `{$table}` WHERE `{$column}` = '{$id}'";
                     DB::execute($sql);
                 }
                 // save log
                 $log = new ApplicationLog();
                 if (logged_user() instanceof Contact) {
                     $log->setTakenById(logged_user()->getId());
                 }
                 $log->setRelObjectId($id);
                 $log->setObjectName($name);
                 $log->setAction(ApplicationLogs::ACTION_DELETE);
                 $log->setIsSilent(true);
                 $log->save();
                 DB::commit();
                 $count++;
             } catch (DBQueryError $e) {
                 DB::rollback();
                 Logger::log("Error delting object in purge_trash: " . $e->getMessage() . "\n" . $e->getSQL() . "\n", Logger::ERROR);
             }
         }
         $ignored = null;
         Hook::fire('after_object_delete_permanently', $object_ids, $ignored);
     }
     return $count;
 }