mirror of https://github.com/itflow-org/itflow
Tweaked Document Versioning logic, this update will update the db to update all exisiting document to update document_parent with the same primary_key ID
This commit is contained in:
parent
8d9f031cab
commit
6b22390604
|
|
@ -232,29 +232,20 @@ $document_parent = intval($row['document_parent']);
|
|||
<div class="card card-body bg-light">
|
||||
<h6><i class="fas fa-history mr-2"></i>Revisions</h6>
|
||||
<?php
|
||||
if($document_parent == 0){
|
||||
|
||||
$sql_document_revisions = mysqli_query($mysqli, "SELECT * FROM documents
|
||||
WHERE document_parent = $document_id
|
||||
OR document_id = $document_id
|
||||
ORDER BY document_created_at DESC"
|
||||
);
|
||||
} else {
|
||||
$sql_document_revisions = mysqli_query($mysqli, "SELECT * FROM documents
|
||||
WHERE document_parent = $document_parent
|
||||
OR document_id = $document_parent
|
||||
ORDER BY document_created_at DESC"
|
||||
);
|
||||
}
|
||||
$sql_document_revisions = mysqli_query($mysqli, "SELECT * FROM documents
|
||||
WHERE document_parent = $document_parent
|
||||
ORDER BY document_created_at DESC"
|
||||
);
|
||||
|
||||
while ($row = mysqli_fetch_array($sql_document_revisions)) {
|
||||
$revision_document_id = intval($row['document_id']);
|
||||
$revision_document_name = nullable_htmlentities($row['document_name']);
|
||||
$revision_document_archived_date = nullable_htmlentities($row['document_archived_at']);
|
||||
$revision_document_created_date = nullable_htmlentities($row['document_created_at']);
|
||||
|
||||
?>
|
||||
<div class="mt-1 <?php if($document_id == $revision_document_id){ echo "text-bold"; } ?>">
|
||||
<i class="fas fa-fw fa-clock text-secondary mr-2"></i><a href="?client_id=<?php echo $client_id; ?>&document_id=<?php echo $revision_document_id; ?>"><?php echo "$revision_document_archived_date - $revision_document_name"; ?></a>
|
||||
<i class="fas fa-fw fa-history text-secondary mr-2"></i><a href="?client_id=<?php echo $client_id; ?>&document_id=<?php echo $revision_document_id; ?>"><?php echo "$revision_document_created_date"; ?></a><?php if($document_parent == $revision_document_id){ echo " (Parent)"; } ?>
|
||||
<a href="post.php?delete_document=<?php echo $revision_document_id; ?>">
|
||||
<i class="fas fa-fw fa-times text-danger ml-2"></i>
|
||||
</a>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="document_id" value="<?php if($document_parent == 0){ echo $document_id; } else { echo $document_parent; } ?>">
|
||||
<input type="hidden" name="document_parent" value="<?php echo $document_parent; ?>">
|
||||
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
|
||||
<div class="modal-body bg-white">
|
||||
|
||||
|
|
|
|||
|
|
@ -1339,11 +1339,20 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
|
|||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.3'");
|
||||
}
|
||||
|
||||
//if (CURRENT_DATABASE_VERSION == '0.8.3') {
|
||||
if (CURRENT_DATABASE_VERSION == '0.8.3') {
|
||||
//Insert queries here required to update to DB version 0.8.4
|
||||
|
||||
mysqli_query($mysqli, "UPDATE `documents` SET `document_parent` = `document_id`");
|
||||
|
||||
// Then, update the database to the next sequential version
|
||||
//mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.4'");
|
||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.4'");
|
||||
}
|
||||
|
||||
//if (CURRENT_DATABASE_VERSION == '0.8.4') {
|
||||
//Insert queries here required to update to DB version 0.8.5
|
||||
|
||||
// Then, update the database to the next sequential version
|
||||
//mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.5'");
|
||||
//}
|
||||
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@
|
|||
* It is used in conjunction with database_updates.php
|
||||
*/
|
||||
|
||||
DEFINE("LATEST_DATABASE_VERSION", "0.8.3");
|
||||
DEFINE("LATEST_DATABASE_VERSION", "0.8.4");
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ if (isset($_POST['add_document'])) {
|
|||
$add_document = mysqli_query($mysqli,"INSERT INTO documents SET document_name = '$name', document_content = '$content', document_content_raw = '$content_raw', document_template = 0, document_folder_id = $folder, document_client_id = $client_id");
|
||||
$document_id = mysqli_insert_id($mysqli);
|
||||
|
||||
// Update field document_parent to be the same id as document ID as this is the only version of the document.
|
||||
mysqli_query($mysqli,"UPDATE documents SET document_parent = $document_id WHERE document_id = $document_id");
|
||||
|
||||
// Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Document', log_action = 'Create', log_description = 'Created $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id");
|
||||
|
||||
|
|
@ -73,7 +76,7 @@ if (isset($_POST['add_document_from_template'])) {
|
|||
$content_raw = sanitizeInput($_POST['name'] . " " . str_replace("<", " <", $row['document_content']));
|
||||
|
||||
// Document add query
|
||||
$add_document = mysqli_query($mysqli,"INSERT INTO documents SET document_name = '$document_name', document_content = '$content', document_content_raw = '$content_raw', document_template = 0, document_folder_id = $folder, document_client_id = $client_id");
|
||||
mysqli_query($mysqli,"INSERT INTO documents SET document_name = '$document_name', document_content = '$content', document_content_raw = '$content_raw', document_template = 0, document_folder_id = $folder, document_client_id = $client_id");
|
||||
|
||||
$document_id = mysqli_insert_id($mysqli);
|
||||
|
||||
|
|
@ -91,6 +94,7 @@ if (isset($_POST['edit_document'])) {
|
|||
validateTechRole();
|
||||
|
||||
$document_id = intval($_POST['document_id']);
|
||||
$document_parent = intval($_POST['document_parent']);
|
||||
$client_id = intval($_POST['client_id']);
|
||||
$name = sanitizeInput($_POST['name']);
|
||||
$content = mysqli_real_escape_string($mysqli,$_POST['content']);
|
||||
|
|
@ -103,16 +107,11 @@ if (isset($_POST['edit_document'])) {
|
|||
|
||||
$new_document_id = mysqli_insert_id($mysqli);
|
||||
|
||||
// Document edit query
|
||||
mysqli_query($mysqli,"UPDATE documents SET document_parent = $new_document_id, document_archived_at = NOW() WHERE document_id = $document_id");
|
||||
// Update the parent ID of the new document to match its new document ID
|
||||
mysqli_query($mysqli,"UPDATE documents SET document_parent = $new_document_id WHERE document_id = $new_document_id");
|
||||
|
||||
// Update all Previous versions with the new parent document ID
|
||||
$sql_documents = mysqli_query($mysqli, "SELECT * FROM documents WHERE document_parent = $document_id");
|
||||
|
||||
while ($row = mysqli_fetch_array($sql_documents)) {
|
||||
$old_document_id = intval($row['document_id']);
|
||||
mysqli_query($mysqli,"UPDATE documents SET document_parent = $new_document_id WHERE document_id = $old_document_id");
|
||||
}
|
||||
// Link all exisiting links with old document with new document
|
||||
mysqli_query($mysqli,"UPDATE documents SET document_parent = $new_document_id, document_archived_at = NOW() WHERE document_parent = $document_id");
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Document', log_action = 'Edit', log_description = '$session_name Edited document $name previous version was kept', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $new_document_id");
|
||||
|
|
|
|||
Loading…
Reference in New Issue