Created
April 22, 2014 14:28
-
-
Save onlime/11181327 to your computer and use it in GitHub Desktop.
fix user preferences in Roundcube webmail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
/* | |
+-----------------------------------------------------------------------+ | |
| bin/fixpreferences.sh | | |
| | | |
| Copyright (c) 2014 Onlime Webhosting (http://www.onlime.ch) | | |
| Licensed under the GNU General Public License version 3. | | |
| | | |
| PURPOSE: | | |
| Fix/search-replace user preferences | | |
+-----------------------------------------------------------------------+ | |
| Author: Philip Iezzi <philip.iezzi[AT]onlime.ch> | | |
+-----------------------------------------------------------------------+ | |
*/ | |
define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' ); | |
require_once INSTALL_PATH . 'program/include/clisetup.php'; | |
$RC = rcube::get_instance(); | |
$DB = $RC->get_dbh(); | |
###################### CONFIGURATION ###################### | |
# search by this preference key | |
$searchKey = 'draft_autosave'; | |
# apply preferences modifications | |
function fixPrefs(array $preferences) | |
{ | |
unset($preferences['draft_autosave']); | |
return $preferences; | |
} | |
########################################################### | |
// Connect to database | |
$DB->db_connect('w'); | |
if (!$DB->is_connected()) { | |
rcube::raise_error("Error connecting to database: " . $DB->is_error(), false, true); | |
} | |
$result = $DB->query( | |
sprintf('SELECT %s, %s FROM %s WHERE %s LIKE ?', | |
$DB->quote_identifier('user_id'), | |
$DB->quote_identifier('preferences'), | |
$DB->quote_identifier($DB->table_name('users')), | |
$DB->quote_identifier('preferences') | |
), "%$searchKey%" | |
); | |
while ($row = $DB->fetch_assoc($result)) { | |
$prefs = unserialize($row['preferences']); | |
$prefs = serialize(fixPrefs($prefs)); | |
echo sprintf("===> Updating preferences of user_id=%s to '%s'", $row['user_id'], $prefs).PHP_EOL; | |
$DB->query( | |
sprintf('UPDATE %s SET %s = ? WHERE %s = ?', | |
$DB->quote_identifier($DB->table_name('users')), | |
$DB->quote_identifier('preferences'), | |
$DB->quote_identifier('user_id') | |
), | |
$prefs, | |
$row['user_id'] | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment