Rewrote 'we' word a little, rewrote mail order to use SQL_INSERTID() instead of anoth...
[mailer.git] / inc / libs / optimize_functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 09/17/2004 *
4  * ===================                          Last change: 09/17/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : optimize_functions.php                           *
8  * -------------------------------------------------------------------- *
9  * Short description : Optimize functions                               *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Optimize-Funktionen                              *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 }
42
43 // Part taken from admin optimize module of PHPNuke (http://www.phpnuke.org)
44 function repairOptimizeDatabase () {
45         $ret = array();
46         $tot_data = '0';
47         $opts = '0';
48         $tot_idx = '0';
49         $total_gain = '0';
50         $tot_all = '0';
51
52         // Get table status
53         $result = SQL_QUERY('SHOW TABLE STATUS FROM `{?__DB_NAME?}`', __FUNCTION__, __LINE__);
54
55         // Init array
56         $ret['total_size'] = '0';
57         $ret['total_tabs'] = SQL_NUMROWS($result);
58         $ret['tables'] = array();
59
60         // Are there entries?
61         if (!SQL_HASZERONUMS($result)) {
62                 // Fetch all rows
63                 while ($row = SQL_FETCHARRAY($result)) {
64                         $tot_data = $row['Data_length'];
65                         $tot_idx  = $row['Index_length'];
66                         $total = $tot_data + $tot_idx;
67                         $total = $total / 1024;
68                         $total = round ($total, 3);
69                         $gain  = $row['Data_free'];
70                         $gain  = $gain / 1024;
71                         $total_gain += $gain;
72                         $gain = round ($gain, 3);
73
74                         // Repair table
75                         $result1 = SQL_QUERY_ESC("REPAIR TABLE `%s`",
76                                 array($row['Name']), __FUNCTION__, __LINE__);
77                         $rep = SQL_FETCHARRAY($result1);
78
79                         // Optimize table
80                         $result1 = SQL_QUERY_ESC("OPTIMIZE TABLE `%s`",
81                                 array($row['Name']), __FUNCTION__, __LINE__);
82                         $opt = SQL_FETCHARRAY($result1);
83
84                         // Add data to array
85                         array_push($ret['tables'], array($row['Name'], $opt['Msg_text'], $rep['Msg_text'], $total, $gain));
86
87                         // Count total table data
88                         $ret['total_size'] += $total;
89                 }
90         }
91         // Total optimized data
92         $total_gain = round ($total_gain,3);
93         $ret['total_gain'] = $total_gain;
94
95         // Insert new row
96         $result = SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_optimize_gain` (`gain`) VALUES (%s)",
97                 array($total_gain), __FUNCTION__, __LINE__);
98
99         // Get total runs and total optimization count
100         $result = SQL_QUERY('SELECT COUNT(`id`) AS `total_rows`, SUM(`gain`) AS `total_optimized` FROM `{?_MYSQL_PREFIX?}_optimize_gain`', __FUNCTION__, __LINE__);
101         $ret = merge_array($ret, SQL_FETCHARRAY($result));
102
103         // Free memory
104         SQL_FREERESULT($result);
105
106         // Return array
107         return $ret;
108 }
109
110 // [EOF]
111 ?>