Permalink
Browse files

Convert change_logs to Module History and added history for bugs'

  • Loading branch information...
1 parent d5624bf commit a1dee07b9c5e894db5587d15cc2951c6488a348c @veggiefrog veggiefrog committed Jun 24, 2012
Showing with 150 additions and 10 deletions.
  1. +58 −0 db/ciniki_bug_history.schema
  2. +23 −1 public/add.php
  3. +3 −2 public/close.php
  4. +58 −0 public/getHistory.php
  5. +2 −2 public/getSettingHistory.php
  6. +3 −3 public/update.php
  7. +3 −2 public/updateSettings.php
View
58 db/ciniki_bug_history.schema
@@ -0,0 +1,58 @@
+#
+# Description
+# -----------
+# This table stores all changes to the bugs module.
+#
+# Fields
+# ------
+# id: The id of the log entry.
+#
+# uuid: The uuid of the log entry. This is used for replication purposes.
+#
+# business_id: The ID of the business the change happened on. Every change
+# must be tied to a business for security reasons.
+#
+# user_id: The user who made the change.
+#
+# session: The id of the current session for the user. A login starts a
+# session, a logout or timeout ends a session.
+#
+# The session and transaction fields are also a system
+# that group changes together.
+#
+# action: The action performed. This is used for rollback purposes.
+#
+# 0 - unknown
+# 1 - add
+# 2 - update
+# 3 - delete
+# 4 - merge
+# 5 - automerge
+#
+# table_name: The table where the change was made.
+#
+# table_key: This should always be the primary key for the table changed.
+#
+# table_field: The changed field.
+#
+# new_value: The new value of the field.
+#
+# log_date: The UTC date and time the change happened.
+#
+create table ciniki_bug_history (
+ id bigint not null auto_increment,
+ uuid char(36) not null,
+ business_id int not null,
+ user_id int not null,
+ session varchar(50) not null,
+ action tinyint unsigned not null,
+ table_name varchar(50) not null,
+ table_key varchar(50) not null,
+ table_field varchar(50) not null,
+ new_value varchar(65000) not null,
+ log_date datetime not null,
+ primary key (id),
+ index (user_id),
+ index (business_id, table_name, table_key, table_field),
+ index (log_date)
+) ENGINE=InnoDB, COMMENT='v1.01';
View
24 public/add.php
@@ -81,6 +81,9 @@ function ciniki_bugs_add($ciniki) {
require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbTransactionStart.php');
require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbTransactionRollback.php');
require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbTransactionCommit.php');
+ require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbQuote.php');
+ require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbInsert.php');
+ require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbAddModuleHistory.php');
$rc = ciniki_core_dbTransactionStart($ciniki, 'bugs');
if( $rc['stat'] != 'ok' ) {
return $rc;
@@ -89,7 +92,6 @@ function ciniki_bugs_add($ciniki) {
//
// Add the bug to the database using the thread libraries
//
- require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbInsert.php');
$strsql = "INSERT INTO ciniki_bugs (business_id, type, priority, status, category, user_id, subject, "
. "source, source_link, options, "
. "date_added, last_updated) VALUES ("
@@ -115,6 +117,26 @@ function ciniki_bugs_add($ciniki) {
}
//
+ // Add all the fields to the change log
+ //
+ $changelog_fields = array(
+ 'type',
+ 'priority',
+ 'status',
+ 'category',
+ 'subject',
+ 'source',
+ 'source_link',
+ 'options',
+ );
+ foreach($changelog_fields as $field) {
+ if( isset($args[$field]) && $args[$field] != '' ) {
+ $rc = ciniki_core_dbAddModuleHistory($ciniki, 'bugs', 'ciniki_bug_history', $args['business_id'],
+ 1, 'ciniki_bugs', $bug_id, $field, $args[$field]);
+ }
+ }
+
+ //
// Add a followup if they included details
//
if( isset($ciniki['request']['args']['content']) && $ciniki['request']['args']['content'] != '' ) {
View
5 public/close.php
@@ -67,7 +67,7 @@ function ciniki_bugs_close($ciniki) {
require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbTransactionRollback.php');
require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbTransactionCommit.php');
require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbUpdate.php');
- require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbAddChangeLog.php');
+ require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbAddModuleHistory.php');
$rc = ciniki_core_dbTransactionStart($ciniki, 'bugs');
if( $rc['stat'] != 'ok' ) {
return $rc;
@@ -86,7 +86,8 @@ function ciniki_bugs_close($ciniki) {
return $rc;
}
- $rc = ciniki_core_dbAddChangeLog($ciniki, 'bugs', $args['business_id'], 'ciniki_bugs', $args['bug_id'], 'status', '60');
+ $rc = ciniki_core_dbAddModuleHistory($ciniki, 'bugs', 'ciniki_bug_history', $args['business_id'],
+ 2, 'ciniki_bugs', $args['bug_id'], 'status', '60');
if( $rc['stat'] != 'ok' ) {
ciniki_core_dbTransactionRollback($ciniki, 'bugs');
return $rc;
View
58 public/getHistory.php
@@ -0,0 +1,58 @@
+<?php
+//
+// Description
+// -----------
+// This function will get the history of a field from the ciniki_core_change_logs table.
+// This allows the user to view what has happened to a data element, and if they
+// choose, revert to a previous version.
+//
+// Info
+// ----
+// Status: beta
+//
+// Arguments
+// ---------
+// api_key:
+// auth_token:
+// business_id: The ID of the business to get the details for.
+// key: The detail key to get the history for.
+//
+// Returns
+// -------
+// <history>
+// <action date="2011/02/03 00:03:00" value="Value field set to" user_id="1" />
+// ...
+// </history>
+// <users>
+// <user id="1" name="users.display_name" />
+// ...
+// </users>
+//
+function ciniki_bugs_getHistory($ciniki) {
+ //
+ // Find all the required and optional arguments
+ //
+ require_once($ciniki['config']['core']['modules_dir'] . '/core/private/prepareArgs.php');
+ $rc = ciniki_core_prepareArgs($ciniki, 'no', array(
+ 'business_id'=>array('required'=>'yes', 'blank'=>'no', 'errmsg'=>'No business specified'),
+ 'bug_id'=>array('required'=>'yes', 'blank'=>'no', 'errmsg'=>'No bug specified'),
+ 'field'=>array('required'=>'yes', 'blank'=>'no', 'errmsg'=>'No field specified'),
+ ));
+ if( $rc['stat'] != 'ok' ) {
+ return $rc;
+ }
+ $args = $rc['args'];
+
+ //
+ // Check access to business_id as owner, or sys admin
+ //
+ require_once($ciniki['config']['core']['modules_dir'] . '/bugs/private/checkAccess.php');
+ $rc = ciniki_bugs_checkAccess($ciniki, $args['business_id'], 'ciniki.bugs.getHistory', 0);
+ if( $rc['stat'] != 'ok' ) {
+ return $rc;
+ }
+
+ require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbGetModuleHistory.php');
+ return ciniki_core_dbGetModuleHistory($ciniki, 'bugs', 'ciniki_bug_history', $args['business_id'], 'ciniki_bugs', $args['bug_id'], $args['field']);
+}
+?>
View
4 public/getSettingHistory.php
@@ -51,7 +51,7 @@ function ciniki_bugs_getSettingHistory($ciniki) {
return $ac;
}
- require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbGetChangeLog.php');
- return ciniki_core_dbGetChangeLog($ciniki, $args['business_id'], 'ciniki_bug_settings', $args['field'], 'detail_value', 'bugs');
+ require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbGetModuleHistory.php');
+ return ciniki_core_dbGetModuleHistory($ciniki, 'bugs', 'ciniki_bug_history', $args['business_id'], 'ciniki_bug_settings', $args['field'], 'detail_value', 'bugs');
}
?>
View
6 public/update.php
@@ -47,7 +47,7 @@ function ciniki_bugs_update($ciniki) {
require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbTransactionCommit.php');
require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbQuote.php');
require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbUpdate.php');
- require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbAddChangeLog.php');
+ require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbAddModuleHistory.php');
$rc = ciniki_core_dbTransactionStart($ciniki, 'bugs');
if( $rc['stat'] != 'ok' ) {
return $rc;
@@ -71,8 +71,8 @@ function ciniki_bugs_update($ciniki) {
foreach($changelog_fields as $field) {
if( isset($args[$field]) ) {
$strsql .= ", $field = '" . ciniki_core_dbQuote($ciniki, $args[$field]) . "' ";
- $rc = ciniki_core_dbAddChangeLog($ciniki, 'bugs', $args['business_id'],
- 'ciniki_bugss', $args['bug_id'], $field, $args[$field]);
+ $rc = ciniki_core_dbAddModuleHistory($ciniki, 'bugs', 'ciniki_bug_history', $args['business_id'],
+ 2, 'ciniki_bugs', $args['bug_id'], $field, $args[$field]);
}
}
$strsql .= "WHERE business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' "
View
5 public/updateSettings.php
@@ -47,7 +47,7 @@ function ciniki_bugs_updateSettings($ciniki) {
require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbTransactionCommit.php');
require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbQuote.php');
require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbInsert.php');
- require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbAddChangeLog.php');
+ require_once($ciniki['config']['core']['modules_dir'] . '/core/private/dbAddModuleHistory.php');
$rc = ciniki_core_dbTransactionStart($ciniki, 'bugs');
if( $rc['stat'] != 'ok' ) {
return $rc;
@@ -87,7 +87,8 @@ function ciniki_bugs_updateSettings($ciniki) {
ciniki_core_dbTransactionRollback($ciniki, 'bugs');
return $rc;
}
- ciniki_core_dbAddChangeLog($ciniki, 'bugs', $args['business_id'], 'ciniki_bug_settings', $field, 'detail_value', $ciniki['request']['args'][$field]);
+ ciniki_core_dbAddModuleHistory($ciniki, 'bugs', 'ciniki_bug_history', $args['business_id'],
+ 2, 'ciniki_bug_settings', $field, 'detail_value', $ciniki['request']['args'][$field]);
}
}

0 comments on commit a1dee07

Please sign in to comment.