mutex_lock(_tbl('entry'))) { Errors::fatalError(get_vocab("failed_to_acquire")); } $sql = "UPDATE " . _tbl('entry') . " SET status=(((~status)&1)<<1)|(private&1), timestamp=timestamp"; $upgrade_handle->command($sql); $upgrade_handle->mutex_unlock(_tbl('entry')); // Then do the repeat table. This is slightly different from the entry table because // it did not previously have a status column. (This was a mistake which we are // going to correct in a momemt.) // Acquire mutex to lock out others trying to update the repeat table (unlikely because // the only other people able to update the database at this stage will be site admins // who know the database username and password, but just in case ...) if (!$upgrade_handle->mutex_lock(_tbl('repeat'))) { Errors::fatalError(get_vocab("failed_to_acquire")); } $sql = "UPDATE " . _tbl('repeat') . " SET status=private&1, timestamp=timestamp"; $upgrade_handle->command($sql); // Now get the approval status for the repeat table. A series is considered to be // awaiting approval if any one of its individual members is awaiting approval. // Find all the rows in the entry table that are members of a series and are awaiting approval $sql = "SELECT DISTINCT repeat_id FROM " . _tbl('entry') . " WHERE repeat_id!=0 AND (status&" . STATUS_AWAITING_APPROVAL . " != 0)"; $res = $upgrade_handle->query($sql); while (false !== ($row = $res->next_row_keyed())) { // Set the approval status for each one $sql = "UPDATE " . _tbl('repeat') . " SET status=status|" . STATUS_AWAITING_APPROVAL . ", timestamp=timestamp WHERE id=" . $row['repeat_id']; $result = $upgrade_handle->command($sql); if ($result != 1) { // Something's gone wrong. No rows have been affected, which should not be the case Errors::fatalError("Failed to update status column in repeat table with approval status."); } } $upgrade_handle->mutex_unlock(_tbl('repeat'));