Skip to content

Commit

Permalink
3.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsteampassnet committed Sep 24, 2024
2 parents 43c1f56 + 6135c1f commit 554afeb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion includes/config/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

define('TP_VERSION', '3.1.2');
define("UPGRADE_MIN_DATE", "1727110744");
define('TP_VERSION_MINOR', '108');
define('TP_VERSION_MINOR', '109');
define('TP_TOOL_NAME', 'Teampass');
define('TP_ONE_DAY_SECONDS', 86400);
define('TP_ONE_WEEK_SECONDS', 604800);
Expand Down
2 changes: 1 addition & 1 deletion includes/tables_integrity.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
{
"table_name": "background_tasks_logs",
"structure_hash": "8fbbbf9027ff6463ebeaf3b0aa60298707c75d039792cd572c8d7d2a096fdf81"
"structure_hash": "db4e45d576146214c1cb7a2a26303316a555823cb36a0b3855fd89a46b0ed7c8"
},
{
"table_name": "cache",
Expand Down
45 changes: 23 additions & 22 deletions install/upgrade_operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
}
// ----<
} elseif ($post_operation === 'populateItemsTable_CreatedAt') {
$finish = populateItemsTable_CreatedAt($pre, $post_nb);
$finish = populateItemsTable_CreatedAt($pre);
} elseif ($post_operation === 'populateItemsTable_UpdatedAt') {
$finish = populateItemsTable_UpdatedAt($pre);
} elseif ($post_operation === 'populateItemsTable_DeletedAt') {
Expand All @@ -167,43 +167,44 @@
}


function populateItemsTable_CreatedAt($pre, $post_nb)
function populateItemsTable_CreatedAt($pre)
{
global $db_link;
// Start transaction to avoid autocommit
mysqli_begin_transaction($db_link, MYSQLI_TRANS_START_READ_WRITE);

// loop on items - created_at
$items = mysqli_query(
$db_link,
"select i.id as id, ls.date as datetime
from `" . $pre . "items` as i
inner join `" . $pre . "log_items` as ls on ls.id_item = i.id
WHERE ls.action = 'at_creation' AND i.created_at IS NULL
LIMIT " . $post_nb.";"
WHERE ls.action = 'at_creation' AND i.created_at IS NULL;"
);

// Empty lists
$updateCases = [];
$ids = [];

// Generate lists of items to update
while ($item = mysqli_fetch_assoc($items)) {
if (empty((string) $item['datetime']) === false && is_null($item['datetime']) === false) {
// update created_at field
mysqli_query(
$db_link,
"UPDATE `" . $pre . "items` SET created_at = '".$item['datetime']."' WHERE id = ".$item['id']
);
$ids[] = $item['id'];
$updateCases[] = "WHEN id = " . $item['id'] . " THEN '" . $item['datetime'] . "'";
}
}

// Is it finished?
$remainingItems = mysqli_num_rows(
mysqli_query(
$db_link,
"SELECT * FROM `" . $pre . "items` WHERE created_at IS NULL"
)
);

// Commit transaction.
mysqli_commit($db_link);
// Update table in unique query
if (!empty($ids)) {
$idsList = implode(',', $ids);
$updateQuery = "
UPDATE `" . $pre . "items`
SET created_at = CASE " . implode(' ', $updateCases) . " END
WHERE id IN (" . $idsList . ")
";
mysqli_query($db_link, $updateQuery);
}

return $remainingItems > 0 ? 0 : 1;
// All items are processed.
return 1;
}

function populateItemsTable_UpdatedAt($pre)
Expand Down

0 comments on commit 554afeb

Please sign in to comment.