本文整理汇总了PHP中GO::getDbConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP GO::getDbConnection方法的具体用法?PHP GO::getDbConnection怎么用?PHP GO::getDbConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GO
的用法示例。
在下文中一共展示了GO::getDbConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fieldExists
public static function fieldExists($tableName, $fieldName)
{
$sql = "SHOW FIELDS FROM `" . $tableName . "`";
$stmt = \GO::getDbConnection()->query($sql);
while ($record = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($record['Field'] == $fieldName) {
return true;
}
}
return false;
}
示例2: executeSqlFile
public static function executeSqlFile($file)
{
$queries = self::getSqlQueries($file);
try {
foreach ($queries as $query) {
\GO::getDbConnection()->query($query);
}
} catch (\Exception $e) {
throw new \Exception("Could not execute query: " . $query . "\n\n" . (string) $e);
}
return true;
}
示例3: run
/**
* The code that needs to be called when the cron is running
*
* If $this->enableUserAndGroupSupport() returns TRUE then the run function
* will be called for each $user. (The $user parameter will be given)
*
* If $this->enableUserAndGroupSupport() returns FALSE then the
* $user parameter is null and the run function will be called only once.
*
* @param CronJob $cronJob
* @param \GO\Base\Model\User $user [OPTIONAL]
*/
public function run(CronJob $cronJob, \GO\Base\Model\User $user = null)
{
$stmt = \GO::getDbConnection()->query("SHOW TABLE STATUS FROM `" . \GO::config()->db_name . "`;");
$database_usage = 0;
while ($r = $stmt->fetch()) {
$database_usage += $r['Data_length'];
$database_usage += $r['Index_length'];
}
\GO::config()->save_setting('database_usage', $database_usage);
$folder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path);
\GO::config()->save_setting('file_storage_usage', $folder->calculateSize());
if (\GO::modules()->postfixadmin) {
$findParams = \GO\Base\Db\FindParams::newInstance()->select('sum(`usage`) AS `usage`')->ignoreAcl()->single();
$result = \GO\Postfixadmin\Model\Mailbox::model()->find($findParams);
\GO::config()->save_setting('mailbox_usage', $result->usage * 1024);
}
}
示例4: foreach
<?php
require 'header.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
try {
foreach ($_POST as $key => $value) {
\GO::config()->{$key} = $value;
}
\GO::config()->save();
$conn = \GO::getDbConnection();
redirect('install.php');
} catch (Exception $e) {
$error = "Could not connect to the database. The database returned this error:<br />" . $e->getMessage();
}
}
printHead();
if (isset($error)) {
errorMessage($error);
}
?>
<h1>Database connection</h1>
<p>
Create a database now and fill in the values to connect to your database.<br />
The database user should have permission to perform select-, insert-, update- and delete queries. It must also be able to lock tables.<br /><br />
If you are upgrading then now is the last time to back up your database! Fill in the fields and click at 'Continue' to upgrade your database structure.
</p>
<div class="cmd">
$ mysql -u root -p<br />
mysql> CREATE DATABASE groupoffice;<br />
示例5: function
$tree = new \GO\Dav\ObjectTree($root);
// The rootnode needs in turn to be passed to the server class
$server = new Sabre\DAV\Server($tree);
$server->debugExceptions = \GO::config()->debug;
$server->subscribeEvent('exception', function ($e) {
\GO::debug((string) $e);
});
//baseUri can also be /webdav/ with:
//Alias /webdav/ /path/to/files.php
$baseUri = strpos($_SERVER['REQUEST_URI'], 'files.php') ? \GO::config()->host . 'modules/dav/files.php/' : '/webdav/';
$server->setBaseUri($baseUri);
$tmpDir = \GO::config()->getTempFolder()->createChild('dav', false);
$locksDir = $tmpDir->createChild('locksdb', false);
$locksDir->create();
// Support for LOCK and UNLOCK
//$lockBackend = new Sabre\DAV\Locks\Backend\FS($locksDir->path());
$lockBackend = new Sabre\DAV\Locks\Backend\PDO(\GO::getDbConnection(), 'dav_locks');
$lockPlugin = new Sabre\DAV\Locks\Plugin($lockBackend);
$server->addPlugin($lockPlugin);
// Support for html frontend
$browser = new Sabre\DAV\Browser\Plugin();
$server->addPlugin($browser);
// Automatically guess (some) contenttypes, based on extesion
$server->addPlugin(new \Sabre\DAV\Browser\GuessContentType());
$auth = new Sabre\DAV\Auth\Plugin($authBackend, \GO::config()->product_name);
$server->addPlugin($auth);
// Temporary file filter
$tempFF = new Sabre\DAV\TemporaryFileFilterPlugin($tmpDir->path());
$server->addPlugin($tempFF);
// And off we go!
$server->exec();
示例6: while
$calStmt = \GO\Calendar\Model\Calendar::model()->findByAttribute('user_id', $category->calendar_id);
while ($calendar = $calStmt->fetch()) {
try {
// Create the new categories for each calendar
$newCategory = new \GO\Calendar\Model\Category();
$newCategory->name = $category->name;
$newCategory->color = $category->color;
$newCategory->calendar_id = $calendar->id;
$newCategory->save();
// Get all events that have the old category and change the category to the new one.
$eventStmt = \GO\Calendar\Model\Event::model()->findByAttributes(array('calendar_id' => $calendar->id, 'category_id' => $category->id));
while ($event = $eventStmt->fetch()) {
//echo "Update event $event->name\n";
$event->category_id = $newCategory->id;
$event->save();
}
} catch (\Exception $e) {
echo $e->getMessage() . "\n";
}
}
}
}
echo "Done creating new categories\n\n";
echo "Remove old categories\n\n";
foreach ($oldCategories as $oldCat) {
// $cat = \GO\Calendar\Model\Category::model()->findByPk($oldCat);
// if($cat)
// $cat->delete();
\GO::getDbConnection()->query("DELETE FROM cal_categories WHERE id=" . $oldCat);
}
echo "Done\n\n";
示例7: actionDuplicateCF
protected function actionDuplicateCF()
{
$stmt = \GO\Customfields\Model\Category::model()->findByModel("GO\\Projects2\\Model\\Project");
$stmt->callOnEach('delete');
$sql = "DROP TABLE IF EXISTS cf_pr2_projects";
\GO::getDbConnection()->query($sql);
$sql = "CREATE TABLE IF NOT EXISTS `cf_pr2_projects` (\n `model_id` int(11) NOT NULL DEFAULT '0',\n PRIMARY KEY (`model_id`)\n) ENGINE=InnoDB;";
\GO::getDbConnection()->query($sql);
$stmt = \GO\Customfields\Model\Category::model()->findByModel("GO\\Projects\\Model\\Project");
foreach ($stmt as $category) {
$category->duplicate(array('extends_model' => "GO\\Projects2\\Model\\Project"));
}
$sql = "INSERT INTO cf_pr2_projects SELECT * FROM cf_pm_projects";
\GO::getDbConnection()->query($sql);
$stmt = \GO\Customfields\Model\Category::model()->findByModel("GO\\Projects2\\Model\\TimeEntry");
$stmt->callOnEach('delete');
$sql = "DROP TABLE IF EXISTS cf_pr2_hours";
\GO::getDbConnection()->query($sql);
$sql = "CREATE TABLE IF NOT EXISTS `cf_pr2_hours` (\n `model_id` int(11) NOT NULL DEFAULT '0',\n PRIMARY KEY (`model_id`)\n) ENGINE=InnoDB;";
\GO::getDbConnection()->query($sql);
$stmt = \GO\Customfields\Model\Category::model()->findByModel("GO\\Projects\\Model\\Hour");
foreach ($stmt as $category) {
$category->duplicate(array('extends_model' => "GO\\Projects2\\Model\\TimeEntry"));
}
$sql = "INSERT INTO cf_pr2_hours SELECT * FROM cf_pm_hours";
\GO::getDbConnection()->query($sql);
}
示例8: actionConvertToInnoDB
protected function actionConvertToInnoDB()
{
$stmt = \GO::getDbConnection()->query("SHOW TABLES");
$stmt->setFetchMode(PDO::FETCH_NUM);
echo '<pre>';
foreach ($stmt as $record) {
if ($record[0] != 'fs_filesearch') {
//filesearch requires fulltext index
$sql = "ALTER TABLE `" . $record[0] . "` ENGINE=InnoDB;";
echo $sql . "\n";
GO::getDbConnection()->query($sql);
}
}
}
示例9: afterDelete
protected function afterDelete()
{
//don't be strict in upgrade process
\GO::getDbConnection()->query("SET sql_mode=''");
$sql = "ALTER TABLE `" . $this->category->customfieldsTableName() . "` DROP `" . $this->columnName() . "`";
try {
$this->getDbConnection()->query($sql);
} catch (\Exception $e) {
trigger_error("Dropping custom field column failed with error: " . $e->getMessage());
}
$this->_clearColumnCache();
return parent::afterDelete();
}
示例10: updateAclMtime
private function updateAclMtime()
{
$sql = "UPDATE go_acl_items SET mtime=unix_timestamp() WHERE id IN (SELECT acl_id FROM go_acl WHERE group_id=" . $this->group_id . ")";
\GO::getDbConnection()->query($sql);
}
示例11: _createTemporaryTable
private function _createTemporaryTable($tableName, $values)
{
if (!isset(self::$_temporaryTables[$tableName])) {
$sql = "CREATE TEMPORARY TABLE `{$tableName}` (\n\t\t\t\t`id` int(11) NOT NULL,\n\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t);";
\GO::getDbConnection()->query($sql);
self::$_temporaryTables[$tableName] = true;
} else {
\GO::getDbConnection()->query("TRUNCATE TABLE `{$tableName}`");
}
$this->sleepingTempTables[$tableName] = $values;
$sql = "INSERT INTO `{$tableName}` (id) VALUES (" . implode('),(', $values) . ")";
\GO::getDbConnection()->query($sql);
}
示例12: define
if (isset($args['c'])) {
define("GO_CONFIG_FILE", $args['c']);
}
}
try {
$exampleUsage = 'sudo -u www-data php /var/www/trunk/www/install/autoinstall.php --adminusername=admin --adminpassword=admin --adminemail=admin@intermesh.dev --modules="email,addressbook,files"';
$requiredArgs = array('adminusername', 'adminpassword', 'adminemail');
foreach ($requiredArgs as $ra) {
if (empty($args[$ra])) {
throw new Exception($ra . " must be supplied.\n\nExample usage:\n\n" . $exampleUsage . "\n\n");
}
}
chdir(dirname(__FILE__));
require '../GO.php';
\GO::setIgnoreAclPermissions();
$stmt = \GO::getDbConnection()->query("SHOW TABLES");
if ($stmt->rowCount()) {
throw new Exception("Automatic installation of Group-Office aborted because database is not empty");
} else {
echo "Database connection established. Database is empty\n";
}
\GO\Base\Util\SQL::executeSqlFile('install.sql');
$dbVersion = \GO\Base\Util\Common::countUpgradeQueries("updates.php");
\GO::config()->save_setting('version', $dbVersion);
\GO::config()->save_setting('upgrade_mtime', \GO::config()->mtime);
$adminGroup = new \GO\Base\Model\Group();
$adminGroup->id = 1;
$adminGroup->name = \GO::t('group_admins');
$adminGroup->save();
$everyoneGroup = new \GO\Base\Model\Group();
$everyoneGroup->id = 2;
示例13: catch
<?php
if (\GO::modules()->addressbook) {
try {
\GO::getDbConnection()->query("ALTER TABLE `fs_folders` DROP `path`");
\GO::getDbConnection()->query("ALTER TABLE `ab_addressbooks` ADD `users` BOOLEAN NOT NULL ");
} catch (PDOException $e) {
//NOP: if column doesn't exists we don't want to hold
}
}
if (\GO::modules()->addressbook) {
$ab = \GO\Addressbook\Model\Addressbook::model()->findSingleByAttribute('users', '1');
//\GO::t('users','base'));
if (!$ab) {
$ab = new \GO\Addressbook\Model\Addressbook();
$ab->name = \GO::t('users');
$ab->users = true;
$ab->save();
$pdo = \GO::getDbConnection();
$pdo->query("INSERT INTO ab_contacts (`addressbook_id`,`first_name`, `middle_name`, `last_name`, `initials`, `title`, `sex`, `birthday`, `email`, `department`, `function`, `home_phone`, `work_phone`, `fax`, `cellular`, `country`, `state`, `city`, `zip`, `address`, `address_no`,`go_user_id`) SELECT {$ab->id},`first_name`, `middle_name`, `last_name`, `initials`, `title`, `sex`, `birthday`, `email`, `department`, `function`, `home_phone`, `work_phone`, `fax`, `cellular`, `country`, `state`, `city`, `zip`, `address`, `address_no`,`id` FROM `go_users` ");
}
}
示例14: concat
<?php
\GO::config()->postfixadmin_autoreply_domain = 'elite.as';
if (!empty(\GO::config()->postfixadmin_autoreply_domain)) {
$sql = "UPDATE pa_aliases SET goto=REPLACE(goto, concat(',',replace(address,'@','#'),'@" . \GO::config()->postfixadmin_autoreply_domain . "'),'')";
echo $sql . "\n";
\GO::getDbConnection()->query($sql);
}
示例15: uninstall
/**
* Delete's the module's tables etc.
*
* @return boolean
*/
public function uninstall()
{
$oldIgnore = \GO::setIgnoreAclPermissions();
// //call deleteUser for each user
// $stmt = Model\User::model()->find(array('ignoreAcl'=>true));
// while($user = $stmt->fetch()){
// call_user_func(array(get_class($this),'deleteUser'), $user);
// }
//Uninstall cron jobs for this module
$cronClasses = $this->findClasses('cron');
foreach ($cronClasses as $class) {
$jobs = Cron\CronJob::model()->findByAttribute('job', $class->getName());
foreach ($jobs as $job) {
$job->delete();
}
}
//delete all models from the Model\ModelType table.
//They are used for faster linking and search cache. Each linkable model is mapped to an id in this table.
$models = $this->getModels();
$modelTypes = array();
foreach ($models as $model) {
$modelType = Model\ModelType::model()->findSingleByAttribute('model_name', $model->getName());
if ($modelType) {
$modelTypes[] = $modelType->id;
$modelType->delete();
}
}
if (!empty($modelTypes)) {
$sql = "DELETE FROM `go_search_cache` WHERE model_type_id IN (" . implode(',', $modelTypes) . ")";
\GO::getDbConnection()->query($sql);
$stmt = GO::getDbConnection()->query('SHOW TABLES');
while ($r = $stmt->fetch()) {
$tableName = $r[0];
if (substr($tableName, 0, 9) == 'go_links_' && !is_numeric(substr($tableName, 9, 1))) {
$sql = "DELETE FROM `{$tableName}` WHERE model_type_id IN (" . implode(',', $modelTypes) . ")";
\GO::getDbConnection()->query($sql);
}
}
}
$sqlFile = $this->path() . 'install/uninstall.sql';
if (file_exists($sqlFile)) {
$queries = Util\SQL::getSqlQueries($sqlFile);
foreach ($queries as $query) {
\GO::getDbConnection()->query($query);
}
}
\GO::clearCache();
\GO::setIgnoreAclPermissions($oldIgnore);
return true;
}