Пример #1
0
 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
0
 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
0
 /**
  * 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
0
<?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&#62; CREATE DATABASE groupoffice;<br />
Пример #5
0
$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
0
        $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
0
 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
0
 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
0
 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
0
 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
0
 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
0
    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
0
<?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
0
<?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
0
 /**
  * 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;
 }
Пример #16
0
<?php

\GO\Base\Db\Columns::$forceLoad = true;
try {
    \GO::getDbConnection()->query("ALTER TABLE `cal_categories` ADD `user_id` INT NOT NULL ; ");
} catch (Exception $e) {
}
try {
    \GO::getDbConnection()->query("update cal_categories set user_id = (select user_id from cal_calendars where id=cal_categories.calendar_id) where calendar_id>0;");
} catch (Exception $e) {
}
$stmt = \GO\Calendar\Model\Category::model()->find(\GO\Base\Db\FindParams::newInstance()->ignoreAcl());
foreach ($stmt as $categoryModel) {
    $aclModel = $categoryModel->setNewAcl($categoryModel->user_id);
    //	$aclModel->addGroup(2, \GO\Base\Model\Acl::WRITE_PERMISSION); // Give 'everybody' group (id: 2) permission.
    $categoryModel->save();
}
Пример #17
0
 /**
  * Creates the PDO instance.
  * When some functionalities are missing in the pdo driver, we may use
  * an adapter class to provides them. mssql will not work correct with PDO
  * @return PDO the pdo instance
  */
 protected function createPdoInstance()
 {
     if (empty($this->connectionString)) {
         return \GO::getDbConnection();
     } else {
         return new PDO($this->connectionString, $this->username, $this->password);
     }
 }