Added a separate databa cleanup script.
authorNik Okuntseff <support@anuko.com>
Sun, 12 Jun 2016 16:49:09 +0000 (16:49 +0000)
committerNik Okuntseff <support@anuko.com>
Sun, 12 Jun 2016 16:49:09 +0000 (16:49 +0000)
WEB-INF/lib/ttTeamHelper.class.php
cron_db_cleanup.php [new file with mode: 0644]

index ed4c519..e76482d 100644 (file)
@@ -758,7 +758,7 @@ class ttTeamHelper {
           $count++;
           $inactive_teams[] = $team_id;
           // Limit the array size for perfomance by allowing this operation on small chunks only.
           $count++;
           $inactive_teams[] = $team_id;
           // Limit the array size for perfomance by allowing this operation on small chunks only.
-          if ($count >= 25) break;
+          if ($count >= 100) break;
         }
       }
       return $inactive_teams;
         }
       }
       return $inactive_teams;
diff --git a/cron_db_cleanup.php b/cron_db_cleanup.php
new file mode 100644 (file)
index 0000000..5e1f259
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+// +----------------------------------------------------------------------+
+// | Anuko Time Tracker
+// +----------------------------------------------------------------------+
+// | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
+// +----------------------------------------------------------------------+
+// | LIBERAL FREEWARE LICENSE: This source code document may be used
+// | by anyone for any purpose, and freely redistributed alone or in
+// | combination with other software, provided that the license is obeyed.
+// |
+// | There are only two ways to violate the license:
+// |
+// | 1. To redistribute this code in source form, with the copyright
+// |    notice or license removed or altered. (Distributing in compiled
+// |    forms without embedded copyright notices is permitted).
+// |
+// | 2. To redistribute modified versions of this code in *any* form
+// |    that bears insufficient indications that the modifications are
+// |    not the work of the original author(s).
+// |
+// | This license applies to this document only, not any other software
+// | that it may be combined with.
+// |
+// +----------------------------------------------------------------------+
+// | Contributors:
+// | https://www.anuko.com/time_tracker/credits.htm
+// +----------------------------------------------------------------------+
+
+/*
+ * cron_db_cleanup.php - this file is an entry point to execute a database cleanup job in Time Tracker.
+ * It must be called externally (for example, from the system cron or task scheduler).
+ */
+
+require_once('initialize.php');
+import('ttTeamHelper');
+
+
+$inactive_teams = ttTeamHelper::getInactiveTeams();
+$count = count($inactive_teams);
+print "$count inactive teams found...<br>\n";
+for ($i = 0; $i < $count; $i++) {
+  print "  deleting team ".$inactive_teams[$i]."<br>\n";
+  $res = ttTeamHelper::delete($inactive_teams[$i]);
+}
+
+$mdb2 = getConnection();
+$mdb2->exec("OPTIMIZE TABLE tt_client_project_binds");
+$mdb2->exec("OPTIMIZE TABLE tt_client_project_binds");
+$mdb2->exec("OPTIMIZE TABLE tt_clients");
+$mdb2->exec("OPTIMIZE TABLE tt_config");
+$mdb2->exec("OPTIMIZE TABLE tt_custom_field_log");
+$mdb2->exec("OPTIMIZE TABLE tt_custom_field_options");
+$mdb2->exec("OPTIMIZE TABLE tt_custom_fields");
+$mdb2->exec("OPTIMIZE TABLE tt_expense_items");
+$mdb2->exec("OPTIMIZE TABLE tt_fav_reports");
+$mdb2->exec("OPTIMIZE TABLE tt_invoices");
+$mdb2->exec("OPTIMIZE TABLE tt_log");
+$mdb2->exec("OPTIMIZE TABLE tt_project_task_binds");
+$mdb2->exec("OPTIMIZE TABLE tt_projects");
+$mdb2->exec("OPTIMIZE TABLE tt_tasks");
+$mdb2->exec("OPTIMIZE TABLE tt_teams");
+$mdb2->exec("OPTIMIZE TABLE tt_tmp_refs");
+$mdb2->exec("OPTIMIZE TABLE tt_user_project_binds");
+$mdb2->exec("OPTIMIZE TABLE tt_users");
+
+print "Done!<br>\n";