migrate ALL the crons to new PDO database class, refs #1287

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2013-11-28 12:35:20 +01:00
parent 990e39cadb
commit 4426ab52d3
15 changed files with 274 additions and 300 deletions

View File

@@ -420,7 +420,7 @@ return Array(
'a2enmod suexec fcgid',
($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'groupadd -f '.$settings['system']['mod_fcgid_httpgroup'] : null,
($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'useradd -s /bin/false -g '.$settings['system']['mod_fcgid_httpgroup'].' '.$settings['system']['mod_fcgid_httpuser'] : null,
($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'chown -R '.$settings['system']['mod_fcgid_httpuser'].':'.$settings['system']['mod_fcgid_httpgroup'].' '.$pathtophpfiles : null,
($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'chown -R '.$settings['system']['mod_fcgid_httpuser'].':'.$settings['system']['mod_fcgid_httpgroup'].' '.FROXLOR_INSTALL_DIR : null,
($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'mkdir -p '.makeCorrectDir($settings['system']['mod_fcgid_configdir']) : null,
($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'mkdir -p '.makeCorrectDir($settings['system']['mod_fcgid_tmpdir']) : null,
($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'a2dismod php5' : null
@@ -439,7 +439,7 @@ return Array(
'a2enmod suexec fastcgi actions',
($settings['phpfpm']['enabled_ownvhost'] == '1') ? 'groupadd -f '.$settings['phpfpm']['vhost_httpgroup'] : null,
($settings['phpfpm']['enabled_ownvhost'] == '1') ? 'useradd -s /bin/false -g '.$settings['phpfpm']['vhost_httpgroup'].' '.$settings['phpfpm']['vhost_httpuser'] : null,
($settings['phpfpm']['enabled_ownvhost'] == '1') ? 'chown -R '.$settings['phpfpm']['vhost_httpuser'].':'.$settings['phpfpm']['vhost_httpgroup'].' '.$pathtophpfiles : null,
($settings['phpfpm']['enabled_ownvhost'] == '1') ? 'chown -R '.$settings['phpfpm']['vhost_httpuser'].':'.$settings['phpfpm']['vhost_httpgroup'].' '.FROXLOR_INSTALL_DIR : null,
($settings['phpfpm']['enabled_ownvhost'] == '1') ? 'a2dismod php5' : null
)
)

View File

@@ -16,10 +16,11 @@
* @package Cron
*
*/
if(@php_sapi_name() != 'cli'
&& @php_sapi_name() != 'cgi'
&& @php_sapi_name() != 'cgi-fcgi')
{
if (@php_sapi_name() != 'cli'
&& @php_sapi_name() != 'cgi'
&& @php_sapi_name() != 'cgi-fcgi'
) {
die('This script will only work in the shell.');
}
@@ -39,17 +40,12 @@ $lockfile = $lockdir . $lockfName;
// normally you should not need to modify this script anymore, if your
// froxlor installation isn't in /var/www/froxlor
define('FROXLOR_INSTALL_DIR', dirname(dirname(__FILE__)));
// TODO remove when not needed anymore
$pathtophpfiles = dirname(dirname(__FILE__));
// should the froxlor installation guessing not work correctly,
// uncomment the following line, and put your path in there!
//$pathtophpfiles = '/var/www/froxlor/';
// create and open the lockfile!
$keepLockFile = false;
$debugHandler = fopen($lockfile, 'w');
fwrite($debugHandler, 'Setting Lockfile to ' . $lockfile . "\n");
fwrite($debugHandler, 'Setting Froxlor installation path to ' . $pathtophpfiles . "\n");
fwrite($debugHandler, 'Setting Froxlor installation path to ' . FROXLOR_INSTALL_DIR . "\n");
// open the lockfile directory and scan for existing lockfiles
$lockDirHandle = opendir($lockdir);
@@ -119,27 +115,28 @@ require FROXLOR_INSTALL_DIR . '/lib/functions.php';
require FROXLOR_INSTALL_DIR . '/lib/tables.inc.php';
fwrite($debugHandler, 'Table definitions included' . "\n");
//Includes the MySQL-Connection-Class
fwrite($debugHandler, 'Database Class has been loaded' . "\n");
$db = new db($sql['host'], $sql['user'], $sql['password'], $sql['db']);
if ($db->link_id == 0) {
// try database connection, it will throw
// and exception itself if failed
try {
Database::query("SELECT 1");
} catch (Exception $e) {
// Do not proceed further if no database connection could be established
fclose($debugHandler);
unlink($lockfile);
die('Froxlor can\'t connect to mysqlserver. Please check userdata.inc.php! Exiting...');
die($e->getMessage());
}
fwrite($debugHandler, 'Database-connection established' . "\n");
unset($sql);
$result = $db->query("SELECT `settingid`, `settinggroup`, `varname`, `value` FROM `" . TABLE_PANEL_SETTINGS . "`");
$result_stmt = Database::query("
SELECT `settingid`, `settinggroup`, `varname`, `value`
FROM `" . TABLE_PANEL_SETTINGS . "`
");
while ($row = $db->fetch_array($result)) {
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
$settings[$row['settinggroup']][$row['varname']] = $row['value'];
}
unset($row);
unset($result);
fwrite($debugHandler, 'Froxlor settings have been loaded from the database' . "\n");
/**
@@ -150,7 +147,7 @@ if ((int)$settings['system']['mod_fcgid'] == 1
&& (int)$settings['system']['mod_fcgid_ownvhost'] == 1
) {
fwrite($debugHandler, 'Checking froxlor file permissions');
$mypath = makeCorrectDir(dirname(dirname(__FILE__))); // /var/www/froxlor, needed for chown
$mypath = makeCorrectDir(FROXLOR_INSTALL_DIR);
$user = $settings['system']['mod_fcgid_httpuser'];
$group = $settings['system']['mod_fcgid_httpgroup'];
// all the files and folders have to belong to the local user
@@ -161,7 +158,6 @@ if ((int)$settings['system']['mod_fcgid'] == 1
// be sure HTMLPurifier's cache folder is writable
safe_exec('chmod -R 0755 '.escapeshellarg(dirname(__FILE__).'/classes/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer'));
if (!isset($settings['panel']['version'])
|| $settings['panel']['version'] != $version
) {

View File

@@ -22,15 +22,6 @@ if ($settings['logger']['log_cron'] == '1') {
fwrite($debugHandler, 'Logging for cron has been shutdown' . "\n");
}
// TODO remove when completely migrated to PDO
$db->close();
fwrite($debugHandler, 'Closing database connection' . "\n");
if (isset($db_root)) {
$db_root->close();
fwrite($debugHandler, 'Closing database rootconnection' . "\n");
}
if ($keepLockFile === true) {
fwrite($debugHandler, '=== Keep lockfile because of exception ===');
}

View File

@@ -63,12 +63,10 @@ unset($key);
$filename = basename($_SERVER['PHP_SELF']);
// keep this for compatibility reasons
$pathtophpfiles = dirname(dirname(__FILE__));
// define default theme for configurehint, etc.
$_deftheme = 'Sparkle';
// define installation directory
define('FROXLOR_INSTALL_DIR', dirname(dirname(__FILE__)));
// check whether the userdata file exists