/** * Tries to create the tables needed for proper functioning of the plugin if * they don't exist already. * * @return boolean TRUE if it succeeds, FALSE otherwise. */ function setupTables() { global $wpdb; $sqlLangs = loadSQLFile('create_langs_table'); $sqlEntries = loadSQLFile('create_entries_table'); $resultLangs = $wpdb->query($sqlLangs); $resultEntries = $wpdb->query($sqlEntries); return $resultLangs && $resultEntries; }
function resetCLCSdb($dbType, $dbConfig) { $dbCon = connectTo($dbConfig, $dbType, FALSE, TRUE); $configFile = "Config/" . $dbType . ".sql"; $dbCon->query("DROP DATABASE IF EXISTS {$dbType}"); $dbCon->query("CREATE DATABASE {$dbType}"); $dbCon->close(); loadSQLFile($dbType, $dbConfig, $configFile); }
LegacyLogger::log("ERROR", 'Upgrade', $e->getMessage()); } } function loadSQLFile($db, $filename) { $lines = explode("\n", file_get_contents($filename)); foreach ($lines as $line) { upgrade($db, $line); } } // move logon_msg and logoff_msg from org_members to preferences try { if (checkIfTableExists($db, "org_members_<myname>")) { $data = $db->query("SELECT * FROM org_members_<myname>"); if (property_exists($data[0], 'logon_msg') || property_exists($data[0], 'logoff_msg')) { loadSQLFile($db, "./core/PREFERENCES/preferences.sql"); foreach ($data as $row) { if (isset($row->logon_msg) && $row->logon_msg != '') { $logon = $db->queryRow("SELECT * FROM preferences_<myname> WHERE sender = ? AND name = ?", $row->name, 'logon_msg'); if ($logon === null) { $db->exec("INSERT INTO preferences_<myname> (sender, name, value) VALUES (?, ?, ?)", $row->name, 'logon_msg', $row->logon_msg); } else { $db->exec("UPDATE preferences_<myname> SET value = ? WHERE sender = ? AND name = ?", $row->logon_msg, $row->name, 'logon_msg'); } } if (isset($row->logoff_msg) && $row->logoff_msg != '') { $logoff = $db->queryRow("SELECT * FROM preferences_<myname> WHERE sender = ? AND name = ?", $row->name, 'logoff_msg'); if ($logoff === null) { $db->exec("INSERT INTO preferences_<myname> (sender, name, value) VALUES (?, ?, ?)", $row->name, 'logoff_msg', $row->logoff_msg); } else { $db->exec("UPDATE preferences_<myname> SET value = ? WHERE sender = ? AND name = ?", $row->logoff_msg, $row->name, 'logoff_msg');
/** * Verifies if the given language already exists in the database. * * Such verification is done by checking if either the short code, * english name or local name are already present in the database. If any * are already present, this procedure considers the given language * to be already registered. * * @param string $shortCode Short code to look for in the database. * @param string $englishName English name of the language to look for in * the database. * @param string $localName Local name of the language to look for in the * database; * * @return bool|int TRUE is any of the parameters given exist in the * database, FALSE otherwise or -1 if an error occured during the * verification. */ public static function exists($shortCode, $englishName, $localName) { global $wpdb; $sql = loadSQLFile('lang_exists'); print $sql; }
/** * Retrieves all entries from the database. The arguments that can be given * to this function limit the entries returned from the database. If no * arguments are given, all entries are returned. * * @param string (optional) The language code that the entries must have to * be returned. If an empty value is given, this parameter is ignored. * @param string (optional) The domain which the entries must belong to be * returned. if an empty value is given, this parameter is ignored. * @param string (optional) The context which the entries must have to be * returned. if an empty value is given, this parameter is ignored. * * @return Entry[]|bool An array with all the entries found in the database. * FALSE in case of error. */ public static function all($langCode = null, $domain = null, $context = null) { global $wpdb; /** * Below we build the conditions to limit which entries to acquire from * the database. Since Wordpress' $wpdb->prepare doesn't support named * nor numeric arguments and we have more than two optional conditions, * we have to order the arguments according to the query we built. */ $optConditions = ''; $optOrder = array(); if (isset($langCode)) { $optConditions .= ' AND `entry_code` = %s'; array_push($optOrder, $langCode); } if (isset($domain)) { $optConditions .= ' AND `entry_domain` = %s'; array_push($optOrder, $domain); } if (isset($context)) { $optConditions .= ' AND `entry_context` = %s'; array_push($optOrder, $context); } $sql = loadSQLFile('all_entries'); $sql = str_ireplace('{OPT_CONDITIONS}', $optConditions, $sql); $results = $wpdb->get_results($wpdb->prepare($sql, @$optOrder[0], @$optOrder[1], @$optOrder[2])); var_dump($results); if ($results) { $entries = array(); foreach ($results as $result) { $entry = new Entry($result->entry_id); array_push($entries, $entry); } return $entries; } else { return false; } }