Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sanitize script to include CiviCRM db backups if they exist #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Get table rows for database and files backups.
* Get table rows for database, (optional) CiviCRM database, and files backups.
*/
function table_rows() {
$paths = array(
Expand All @@ -11,21 +11,23 @@ function table_rows() {
);

foreach ($paths as $path => $name) {
$databases = array();
$files = array();

exec("ls $path/sanitized/*.sql.gz", $databases);
$dbs = $dbs_civi = $files = array();
exec("ls $path/sanitized/*.sql.gz", $dbs);
exec("ls $path/sanitized_civi/*.sql.gz", $dbs_civi);
exec("ls $path/files_backups/*.tar.gz", $files);
foreach (array_reverse($databases) as $id => $database) {
create_row($name, $database, array_reverse($files)[$id]);
$r_dbs = array_reverse($dbs);
$r_dbs_civi = array_reverse($dbs_civi);
$r_files = array_reverse($files);
foreach ($r_dbs as $id => $db) {
create_row($name, $db, $r_files[$id], (isset($r_dbs_civi[$id]) ? $r_dbs_civi[$id] : ''));
}
}
}

/**
* Print the HTML for a single table row.
*/
function create_row($name, $db_path, $file_path) {
function create_row($name, $db_path, $file_path, $db_civi_path) {
$class = '';
$db_path_parts = explode('/', $db_path);
$db_filename_parts = explode('-', $db_path_parts[2]);
Expand All @@ -40,12 +42,13 @@ function create_row($name, $db_path, $file_path) {

$host = filter_input(INPUT_SERVER, 'HTTP_HOST');
$db_link = sprintf('<a href="https://%s/%s">Database</a>', $host, $db_path);
$db_civi_link = sprintf('<a href="https://%s/%s">CiviCRM</a>', $host, $db_civi_path);
$file_link = sprintf('<a href="https://%s/%s">Files</a>', $host, $file_path);

print '<tr class="' . $class . '">
<td>' . $name . '</td>
<td>' . $date . '</td>
<td>' . $db_link . ' :: ' . $file_link . '</td>
<td>' . $db_link . ' :: ' . (!empty($db_civi_path) ? $db_civi_link . ' :: ' : '') . $file_link . '</td>
</tr>';
}
?>
Expand Down