/** * get create table statement * * @param Setup_Backend_Schema_Table_Abstract $_table * @return string */ public function getCreateStatement(Setup_Backend_Schema_Table_Abstract $_table) { $statement = "CREATE TABLE IF NOT EXISTS `" . SQL_TABLE_PREFIX . $_table->name . "` (\n"; $statementSnippets = array(); foreach ($_table->fields as $field) { if (isset($field->name)) { $statementSnippets[] = $this->getFieldDeclarations($field); } } foreach ($_table->indices as $index) { if ($index->foreign) { $statementSnippets[] = $this->getForeignKeyDeclarations($index); } else { $statementSnippets[] = $this->getIndexDeclarations($index); } } $statement .= implode(",\n", $statementSnippets) . "\n)"; if (isset($_table->engine)) { $statement .= " ENGINE=" . $_table->engine . " DEFAULT CHARSET=" . $_table->charset; } else { $statement .= " ENGINE=InnoDB DEFAULT CHARSET=utf8 "; } if (isset($_table->comment)) { $statement .= " COMMENT='" . $_table->comment . "'"; } if (Setup_Core::isLogLevel(Zend_Log::TRACE)) { Setup_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $statement); } return $statement; }
/** * handler for JSON api requests * * @return JSON */ public function handle() { try { // init server and request first $server = new Zend_Json_Server(); $server->setClass('Setup_Frontend_Json', 'Setup'); $server->setClass('Tinebase_Frontend_Json', 'Tinebase'); $server->setAutoHandleExceptions(false); $server->setAutoEmitResponse(false); $request = new Zend_Json_Server_Request_Http(); Setup_Core::initFramework(); $method = $request->getMethod(); $jsonKey = isset($_SERVER['HTTP_X_TINE20_JSONKEY']) ? $_SERVER['HTTP_X_TINE20_JSONKEY'] : ''; Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' is JSON request. method: ' . $method); $anonymnousMethods = array('Setup.getAllRegistryData', 'Setup.login', 'Tinebase.getAvailableTranslations', 'Tinebase.getTranslations', 'Tinebase.setLocale'); if (!Setup_Core::configFileExists()) { $anonymnousMethods = array_merge($anonymnousMethods, array('Setup.envCheck')); } // check json key for all methods but some exceptoins if (!in_array($method, $anonymnousMethods) && Setup_Core::configFileExists() && (empty($jsonKey) || $jsonKey != Setup_Core::get('jsonKey') || !Setup_Core::isRegistered(Setup_Core::USER))) { if (!Setup_Core::isRegistered(Setup_Core::USER)) { Setup_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . ' Attempt to request a privileged Json-API method without authorisation from "' . $_SERVER['REMOTE_ADDR'] . '". (session timeout?)'); throw new Tinebase_Exception_AccessDenied('Not Authorised', 401); } else { Setup_Core::getLogger()->WARN(__METHOD__ . '::' . __LINE__ . ' Fatal: got wrong json key! (' . $jsonKey . ') Possible CSRF attempt!' . ' affected account: ' . print_r(Setup_Core::getUser(), true) . ' request: ' . print_r($_REQUEST, true)); throw new Tinebase_Exception_AccessDenied('Not Authorised', 401); } } $response = $server->handle($request); } catch (Exception $exception) { $response = $this->_handleException($server, $request, $exception); } echo $response; }
/** * Call {@see _initialize} on an instance of the concrete Setup_Initialize class for the given {@param $_application} * * @param Tinebase_Model_Application $_application * @param array | optional $_options * @return void */ public static function initialize(Tinebase_Model_Application $_application, $_options = null) { $applicationName = $_application->name; $classname = "{$applicationName}_Setup_Initialize"; $instance = new $classname(); Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Initializing application: ' . $applicationName); $instance->_initialize($_application, $_options); }
/** * update to 4.1 * - drop column jpegphoto */ public function update_0() { try { $this->_backend->dropCol('addressbook', 'jpegphoto'); } catch (Zend_Db_Statement_Exception $zdse) { Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' ' . $zdse->getMessage()); } $this->setTableVersion('addressbook', 12); $this->setApplicationVersion('Addressbook', '4.1'); }
/** * install new applications * * @param array $applicationNames application names to install * @param array | optional $options */ public function installApplications($applicationNames, $options = null) { if (is_array($applicationNames)) { $this->_controller->installApplications($applicationNames, $options); $result = TRUE; } else { Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not handle param $applicationNames: ' . $decodedNames); $result = FALSE; } return array('success' => $result, 'setupRequired' => $this->_controller->setupRequired()); }
/** * uninitialize application * * @param Tinebase_Model_Application $_application * @param array | optional $_options * @return void */ protected function _uninitialize(Tinebase_Model_Application $_application, $_options = null) { $reflectionClass = new ReflectionClass($this); $methods = $reflectionClass->getMethods(); foreach ($methods as $method) { $methodName = $method->name; if (strpos($methodName, '_uninitialize') === 0 && $methodName !== '_uninitialize') { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Calling uninit function ' . get_class($this) . '::' . $methodName); $this->{$methodName}($_application, $_options); } } }
/** * initialize application * * @param Tinebase_Model_Application $_application * @param array | optional $_options * @return void */ protected function _initialize(Tinebase_Model_Application $_application, $_options = null) { $this->_createInitialRights($_application); $reflectionClass = new ReflectionClass($this); $methods = $reflectionClass->getMethods(); foreach ($methods as $method) { $methodName = $method->name; if (preg_match('/^_initialize.+/', $methodName)) { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Calling init function ' . get_class($this) . '::' . $methodName); $this->{$methodName}($_application, $_options); } } }
/** * * init folders */ public function _initializeFolders(Tinebase_Model_Application $_application, $_options = null) { // initialize folders for installed apps foreach (Tinebase_Application::getInstance()->getApplications() as $app) { $reflectionClass = new ReflectionClass($app->name . '_Setup_Initialize'); $methods = $reflectionClass->getMethods(); foreach ($methods as $method) { $methodName = $method->name; if ($method->name == '_initializeFilemanagerFolder') { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Initializing filemanager folder for application: ' . $app->name); $class = $reflectionClass->newInstance(); $class->_initializeFilemanagerFolder($app); } } } }
/** * identify base event via new base_event_id field instead of UID */ public function update_8() { /* find possibly broken events SELECT group_concat(id), uid, count(id) as cnt from tine20_cal_events WHERE rrule IS NOT NULL GROUP BY uid HAVING cnt > 1; */ $declaration = new Setup_Backend_Schema_Field_Xml(' <field> <name>base_event_id</name> <type>text</type> <length>40</length> </field>'); $this->_backend->addCol('cal_events', $declaration); $declaration = new Setup_Backend_Schema_Index_Xml(' <index> <name>base_event_id</name> <field> <name>base_event_id</name> </field> </index>'); $this->_backend->addIndex('cal_events', $declaration); // find all events with rrule $events = $this->_db->query("SELECT " . $this->_db->quoteIdentifier('id') . ', ' . $this->_db->quoteIdentifier('uid') . ', ' . $this->_db->quoteIdentifier('container_id') . ', ' . $this->_db->quoteIdentifier('created_by') . " FROM " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_events") . " WHERE " . $this->_db->quoteIdentifier("rrule") . " IS NOT NULL" . " AND " . $this->_db->quoteIdentifier("is_deleted") . " = " . $this->_db->quote(0, Zend_Db::INT_TYPE))->fetchAll(Zend_Db::FETCH_ASSOC); // update all exdates in same container foreach ($events as $event) { $this->_db->query("UPDATE " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_events") . " SET " . $this->_db->quoteIdentifier('base_event_id') . ' = ' . $this->_db->quote($event['id']) . " WHERE " . $this->_db->quoteIdentifier('uid') . ' = ' . $this->_db->quote($event['uid']) . " AND " . $this->_db->quoteIdentifier("container_id") . ' = ' . $this->_db->quote($event['container_id']) . " AND " . $this->_db->quoteIdentifier("recurid") . " IS NOT NULL" . " AND " . $this->_db->quoteIdentifier("is_deleted") . " = " . $this->_db->quote(0, Zend_Db::INT_TYPE)); } // find all container move exdates $danglingExdates = $this->_db->query("SELECT " . $this->_db->quoteIdentifier('uid') . ', ' . $this->_db->quoteIdentifier('id') . ', ' . $this->_db->quoteIdentifier('created_by') . " FROM " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_events") . " WHERE " . $this->_db->quoteIdentifier("recurid") . " IS NOT NULL" . " AND " . $this->_db->quoteIdentifier("base_event_id") . " IS NULL" . " AND " . $this->_db->quoteIdentifier("is_deleted") . " = " . $this->_db->quote(0, Zend_Db::INT_TYPE))->fetchAll(Zend_Db::FETCH_ASSOC); // try to match by creator foreach ($danglingExdates as $exdate) { $possibleBaseEvents = array(); $matches = array_filter($events, function ($event) use($exdate, $possibleBaseEvents) { if ($event['uid'] == $exdate['uid']) { $possibleBaseEvents[] = $event; return $event['created_by'] == $exdate['created_by']; } return false; }); switch (count($matches)) { case 0: // no match :-( if (count($possibleBaseEvents) == 0) { // garbage? exdate without any base event Setup_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " dangling exdate with id {$exdate['id']}"); continue 2; } Setup_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " no match for exdate with id {$exdate['id']}"); $baseEvent = current($possibleBaseEvents); break; case 1: // exact match :-) $baseEvent = current($matches); break; default: // to much matches :-( Setup_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " multiple matches for exdate with id {$exdate['id']}"); $baseEvent = current($matches); } $this->_db->query("UPDATE " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_events") . " SET " . $this->_db->quoteIdentifier('base_event_id') . ' = ' . $this->_db->quote($baseEvent['id']) . " WHERE " . $this->_db->quoteIdentifier('id') . ' = ' . $this->_db->quote($exdate['id'])); } $this->setTableVersion('cal_events', '10'); $this->setApplicationVersion('Calendar', '8.9'); }
/** * update to 4.3 * - add index for applications.status */ public function update_2() { if ($this->getTableVersion('applications') < 2) { $declaration = new Setup_Backend_Schema_Index_Xml(' <index> <name>status</name> <field> <name>status</name> </field> </index> '); try { $this->_backend->addIndex('applications', $declaration); } catch (Zend_Db_Statement_Exception $zdse) { Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' ' . $zdse->getMessage()); } $this->setTableVersion('applications', '7'); } $this->setApplicationVersion('Tinebase', '4.3'); }
/** * clear cache * * @return void */ protected function _clearCache() { // setup cache (via tinebase because it is disabled in setup by default) Tinebase_Core::setupCache(TRUE); Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Clearing cache ...'); // clear cache $cache = Setup_Core::getCache()->clean(Zend_Cache::CLEANING_MODE_ALL); // deactivate cache again Tinebase_Core::setupCache(FALSE); }
/** * create inital rights * * @todo make hard coded role names ('user role' and 'admin role') configurable * * @param Tinebase_Application $application * @return void */ public static function createInitialRights(Tinebase_Model_Application $_application) { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Creating initial rights for application ' . $_application->name); $allRights = Tinebase_Application::getInstance()->getAllRights($_application->getId()); $userRights = static::$_userRoleRights; if (in_array(Tinebase_Acl_Rights::USE_PERSONAL_TAGS, $allRights)) { $userRights[] = Tinebase_Acl_Rights::USE_PERSONAL_TAGS; } $roleRights = array('user role' => $userRights, 'admin role' => $allRights); foreach ($roleRights as $roleName => $rights) { try { $role = Tinebase_Acl_Roles::getInstance()->getRoleByName($roleName); } catch (Tinebase_Exception_NotFound $tenf) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' ' . $tenf->getMessage()); continue; } foreach ($rights as $right) { try { Tinebase_Acl_Roles::getInstance()->addSingleRight($role->getId(), $_application->getId(), $right); } catch (Exception $e) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Cannot add right: ' . $right . ' for application: ' . $_application->name . ' - ' . $roleName . ' - ' . print_r($e->getMessage(), true)); } } } }
/** * returns one config value identified by config name and application id * -> value in config.inc.php overwrites value in db if $_fromFile is TRUE * * @deprecated * @param string $_name config name/key * @param string $_applicationId application id [optional] * @param mixed $_default the default value [optional] * @param boolean $_fromFile get from config.inc.php [optional] * @return Tinebase_Model_Config the config record * @throws Tinebase_Exception_NotFound */ public function getConfig($_name, $_applicationId = NULL, $_default = NULL, $_fromFile = TRUE) { $applicationId = $_applicationId !== NULL ? Tinebase_Model_Application::convertApplicationIdToInt($_applicationId) : Tinebase_Application::getInstance()->getApplicationByName('Tinebase')->getId(); $result = $this->_loadConfig($_name, $applicationId); if (!$result) { $result = new Tinebase_Model_Config(array('application_id' => $applicationId, 'name' => $_name, 'value' => $_default), TRUE); } // check config.inc.php and get value from there $configFileData = $this->_getConfigFileData(); if ($_fromFile && array_key_exists($_name, $configFileData)) { Setup_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Overwriting config setting "' . $_name . '" with value from config.inc.php.'); $result->value = $configFileData[$_name]; } return $result; }
/** * Update messenger config data * * @param array $data * @return array [success status] */ public function saveMessengerConfig($data) { Setup_Core::getLogger()->debug('INICIANDO CONFIG MESSENGER ===================='); $this->_controller->saveMessengerConfig($data); return array('success' => true); }
/** * update to 0.28 * - repair db charset for users with non default utf8 client charset */ public function update_27() { $config = Setup_Core::get(Setup_Core::CONFIG); $tableprefix = $config->database->tableprefix; // have a second db connection with default charset $orgDb = Zend_Db::factory('Pdo_Mysql', $config->database->toArray()); // fix for signed / unsigned problem $declaration = new Setup_Backend_Schema_Field_Xml(' <field> <name>id</name> <type>integer</type> <autoincrement>true</autoincrement> </field> '); $this->_backend->alterCol('addressbook', $declaration); /** addressbook: store image in separate table **/ $tableDefinition = ' <table> <name>addressbook_image</name> <version>1</version> <declaration> <field> <name>contact_id</name> <type>integer</type> <notnull>true</notnull> </field> <field> <name>image</name> <type>blob</type> </field> <index> <name>contact_id</name> <primary>true</primary> <field> <name>contact_id</name> </field> </index> <index> <name>addressbook_image::contact_id-addressbook::id</name> <field> <name>contact_id</name> </field> <foreign>true</foreign> <reference> <table>addressbook</table> <field>id</field> <ondelete>CASCADE</ondelete> </reference> </index> </declaration> </table> '; $table = Setup_Backend_Schema_Table_Factory::factory('String', $tableDefinition); $this->_backend->createTable($table); $select = $orgDb->select()->from("{$tableprefix}addressbook", array('id'))->where($orgDb->quoteIdentifier('jpegphoto') . " IS NOT NULL"); $contactIds = $orgDb->fetchAll($select); foreach ($contactIds as $contactId) { $contactId = $contactId['id']; $select = $orgDb->select()->from("{$tableprefix}addressbook", array('id', 'jpegphoto'))->where($orgDb->quoteInto($orgDb->quoteIdentifier('id') . ' = ?', $contactId)); $imageData = $orgDb->fetchRow($select); $orgDb->insert("{$tableprefix}addressbook_image", array('contact_id' => $imageData['id'], 'image' => base64_encode($imageData['jpegphoto']))); } $this->_backend->dropCol('addressbook', 'jpegphoto'); /** convert serialized object into json objects **/ $select = $orgDb->select()->from("{$tableprefix}filter", array('id', 'filters')); $filters = $orgDb->fetchAll($select); foreach ($filters as $filter) { $filterObject = unserialize($filter['filters']); $orgDb->update("{$tableprefix}filter", array('filters' => Zend_Json::encode($filterObject)), $orgDb->quoteInto($orgDb->quoteIdentifier('id') . ' = ?', $filter['id'])); } /** convert db contenets for installations which had a clientcharset != utf8 **/ $originalCharset = Tinebase_Helper::array_value('Value', Tinebase_Helper::array_value(0, $orgDb->query("SHOW VARIABLES LIKE 'character_set_client'")->fetchAll())); if (strtolower($originalCharset) != 'utf8') { $this->_db->query("SET FOREIGN_KEY_CHECKS=0"); $orgDb->query("SET FOREIGN_KEY_CHECKS=0"); // build the list of tables to convert $tables = array(); $rawTables = $this->_db->query("SHOW TABLES")->fetchAll(); foreach ($rawTables as $rawTable) { $tableName = array_values($rawTable); $tableName = $tableName[0]; if (preg_match("/^{$tableprefix}/", $tableName) && $tableName != "{$tableprefix}addressbook_image") { $tables[] = $tableName; } } // the actual charset conversion is done by the db. foreach ($tables as $tableName) { Setup_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Converting table ' . $tableName); //$this->_db->query("SET character_set_client = '$originalCharset'"); $select = $orgDb->select()->from($tableName); $result = $orgDb->fetchAll($select); $orgDb->query("TRUNCATE TABLE " . $this->_db->quoteIdentifier($tableName)); //$this->_db->query("SET character_set_client = 'utf8'"); foreach ($result as $row) { try { $this->_db->insert($tableName, $row); } catch (Zend_Db_Statement_Exception $zdse) { Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' ' . $zdse->getMessage()); // try to convert strings if failure if (preg_match('/(description|title|note|old_value|org_name|adr_one_street)/', $zdse->getMessage(), $match)) { $field = $match[1]; Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Converting field ' . $field . (isset($row['id']) || array_key_exists('id', $row) ? ' of record ' . $row['id'] : '')); $row[$field] = utf8_encode($row[$field]); $this->_db->insert($tableName, $row); } else { Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not convert field'); throw $zdse; } } } } $this->_db->query("SET FOREIGN_KEY_CHECKS=1"); } $orgDb->closeConnection(); $this->setApplicationVersion('Tinebase', '0.28'); }
/** * update to 4.9 * - add seq to async job */ public function update_8() { $declaration = new Setup_Backend_Schema_Field_Xml(' <field> <name>seq</name> <type>integer</type> <length>64</length> </field> '); try { $this->_backend->addCol('async_job', $declaration, 5); $declaration = new Setup_Backend_Schema_Index_Xml(' <index> <name>seq</name> <unique>true</unique> <field> <name>seq</name> </field> </index> '); $this->_backend->addIndex('async_job', $declaration); } catch (Exception $e) { // table might have duplicate seqs $this->_backend->truncateTable('async_job'); try { $this->_backend->addIndex('async_job', $declaration); } catch (Exception $e) { // already done: do nothing Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not add index: ' . $e); } } $this->setTableVersion('async_job', '2'); $this->setApplicationVersion('Tinebase', '4.9'); }
/** * checks the environment * * @return array with success/failure values for the given attributes * */ private function _check() { foreach ($this->values as $key => $value) { if ($value['tag'] == 'ENVIROMENT') { switch ($value['attributes']['NAME']) { case 'Zend': $required = $value['attributes']['VERSION']; $zend = Zend_Version::VERSION; $operator = $value['attributes']['OPERATOR'] == 'biggerThan' ? '>' : '<'; $text = $value['attributes']['NAME'] . ' ' . $operator . ' ' . $required; if (version_compare($zend, $required, $operator)) { $data[] = array($text, 'SUCCESS'); } else { $data[] = array($text . ' (version is ' . $zend . ')', 'FAILURE'); } break; case 'PHP': if (version_compare($value['attributes']['VERSION'], phpversion(), '<=')) { $data[] = array($value['attributes']['NAME'], 'SUCCESS'); } else { Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' PHP version incompatible: ' . phpversion() . ' < ' . $value['attributes']['VERSION']); $data[] = array($value['attributes']['NAME'], 'FAILURE'); } break; case 'MySQL': // get setup controller for database connection if (Setup_Core::configFileExists()) { $dbConfig = Tinebase_Core::getConfig()->database; $hostnameWithPort = isset($dbConfig->port) ? $dbConfig->host . ':' . $dbConfig->port : $dbConfig->host; $link = @mysql_connect($hostnameWithPort, $dbConfig->username, $dbConfig->password); if (!$link) { //die('Could not connect to mysql database: ' . mysql_error()); Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . 'Could not connect to mysql database: ' . mysql_error()); Setup_Core::set(Setup_Core::CHECKDB, FALSE); } $mysqlVersion = @mysql_get_server_info(); } else { $mysqlVersion = @mysql_get_client_info(); } // some version strings have more than just the version preg_match('/\\d+\\.\\d+\\.\\d+/', $mysqlVersion, $matches); $mysqlVersion = is_array($matches) ? $matches[0] : $mysqlVersion; $text = $value['attributes']['NAME']; if (version_compare($value['attributes']['VERSION'], $mysqlVersion, '<=')) { $data[] = array($text, 'SUCCESS'); } else { Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' MySQL version incompatible: ' . $mysqlVersion . ' < ' . $value['attributes']['VERSION']); $data[] = array($text, 'FAILURE'); } break; case 'PgSQL': $pgsqlVersion = '0.0.0'; // get setup controller for database connection if (Setup_Core::configFileExists()) { $dbConfig = Tinebase_Core::getConfig()->database; $hostname = $dbConfig->host; $port = isset($dbConfig->port) ? $dbConfig->port : '5432'; $user = $dbConfig->username; $password = $dbConfig->password; $link = @pg_connect("host={$hostname} port={$port} user={$user} password={$password}"); if (PGSQL_CONNECTION_BAD === pg_connection_status($link)) { //die('Could not connect to postgresql database: ' . pg_errormessage()); Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . 'Could not connect to postgresql database: ' . pg_errormessage()); Setup_Core::set(Setup_Core::CHECKDB, FALSE); } else { $pgsqlVersion = @pg_version($link); $pgsqlVersion = $pgsqlVersion['server']; } } $text = $value['attributes']['NAME']; if (version_compare($value['attributes']['VERSION'], $pgsqlVersion, '<=')) { $data[] = array($text, 'SUCCESS'); } else { Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' PostgreSQL version incompatible: ' . $pgsqlVersion . ' < ' . $value['attributes']['VERSION']); $data[] = array($text, 'FAILURE'); } break; default: $data[] = array($value['attributes']['NAME'], 'FAILURE'); break; } } else { if ($value['tag'] == 'EXTENSION') { //print_r($this->loadedExtensions); foreach ($value as $extensionArray) { if (is_array($extensionArray)) { $succeeded = false; if (in_array($extensionArray['NAME'], $this->loadedExtensions)) { $passed[] = true; if ($this->values[$key + 1]['tag'] == 'INISET') { $iniSettings = ini_get_all($extensionArray['NAME']); //print_r($iniSettings); $i = 1; while ($values[$key + $i]['tag'] == 'INISET') { switch ($values[$key + $i]['attributes']['OPERATOR']) { case '<=': if (!$iniSettings[$values[$key + $i]['attributes']['NAME']][$values[$key + $i]['attributes']['SCOPE']] <= $values[$key + $i]['attributes']['VALUE']) { $passed[] = false; } break; case '==': if (!$iniSettings[$values[$key + $i]['attributes']['NAME']][$values[$key + $i]['attributes']['SCOPE']] == $values[$key + $i]['attributes']['VALUE']) { $passed[] = false; } break; case '>=': if (!$iniSettings[$values[$key + $i]['attributes']['NAME']][$values[$key + $i]['attributes']['SCOPE']] >= $values[$key + $i]['attributes']['VALUE']) { $passed[] = false; } break; default: break; } $i++; } } // end INISET if (!in_array(false, $passed)) { $succeeded = true; } unset($passed); unset($iniSettings); } if ($succeeded) { $data[] = array($extensionArray['NAME'], 'SUCCESS'); } else { $data[] = array($extensionArray['NAME'], 'FAILURE'); } } } } } // end EXTENSION } // end foreach return $data; }
/** * update to 8.15 * * move keyFieldConfig defaults to config files */ public function update_14() { // either put default to DB or delete form DB $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config')); $configRecords = $cb->getAll(); // iterate installed apps foreach (Tinebase_Application::getInstance()->getApplications() as $application) { try { // get config $config = Tinebase_Config::getAppConfig($application->name); if (!method_exists($config, 'getProperties')) { continue; } foreach ($config->getProperties() as $name => $property) { if ($property['type'] == Tinebase_Config_Abstract::TYPE_KEYFIELD_CONFIG) { $dbConfig = $config->get($name); $dbConfigRecords = $dbConfig['records']->toArray(); $defaultRecords = isset($property['default']['records']) ? $property['default']['records'] : null; if ($defaultRecords && json_encode($dbConfigRecords) != json_encode($defaultRecords)) { // set default value if (array_key_exists('default', $property['default'])) { $dbConfig->default = $property['default']['default']; $config->set($name, $dbConfig->toArray()); } } else { // delete default config $configRecord = $configRecords->filter('application_id', $application->getId())->filter('name', $name)->getFirstRecord(); if ($configRecord) { $cb->delete($configRecord->getId()); } } } } } catch (Exception $e) { Setup_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' could not migrate keyFieldConfig ' . $e); } } $this->setApplicationVersion('Tinebase', '8.15'); }
/** * update existing definition or create new from file * - use backend functions (create/update) directly because we do not want any default controller handling here * - calling function needs to make sure that user has admin right! * * @param string $_filename * @param Tinebase_Model_Application $_application * @param string $_name * @return Tinebase_Model_ImportExportDefinition */ public function updateOrCreateFromFilename($_filename, $_application, $_name = NULL) { $definition = $this->getFromFile($_filename, $_application->getId(), $_name); // try to get definition and update if it exists try { $existing = $this->getByName($definition->name); Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Updating definition: ' . $definition->name); $copyFields = array('filename', 'plugin_options', 'description'); foreach ($copyFields as $field) { $existing->{$field} = $definition->{$field}; } $result = $this->_backend->update($existing); } catch (Tinebase_Exception_NotFound $tenf) { // does not exist Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Creating import/export definion from file: ' . $_filename); $result = $this->_backend->create($definition); } return $result; }
/** * initializes the database connection * * @return boolean * * @todo try to write to db, if it fails: self::set(Setup_Core::CHECKDB, FALSE); */ public static function setupDatabaseConnection() { $dbcheck = FALSE; // check database first if (self::configFileExists()) { $dbConfig = Tinebase_Core::getConfig()->database; if ($dbConfig->adapter === self::PDO_MYSQL && (!defined(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY) || !defined(PDO::MYSQL_ATTR_INIT_COMMAND))) { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' MySQL PDO constants not defined.'); return FALSE; } try { parent::setupDatabaseConnection(); $serverVersion = self::getDb()->getServerVersion(); switch ($dbConfig->adapter) { case self::PDO_MYSQL: if (version_compare(self::MYSQL_MINIMAL_VERSION, $serverVersion, '<')) { $dbcheck = TRUE; } else { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' MySQL server version incompatible! ' . $serverVersion . ' < ' . self::MYSQL_MINIMAL_VERSION); } break; case self::ORACLE: if (version_compare(self::ORACLE_MINIMAL_VERSION, $serverVersion, '<')) { self::set(Setup_Core::CHECKDB, TRUE); } else { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Oracle server version incompatible! ' . $serverVersion . ' < ' . self::ORACLE_MINIMAL_VERSION); } $dbcheck = TRUE; break; case self::PDO_PGSQL: if (version_compare(self::PGSQL_MINIMAL_VERSION, $serverVersion, '<')) { $dbcheck = TRUE; } else { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' PostgreSQL server version incompatible! ' . $serverVersion . ' < ' . self::PGSQL_MINIMAL_VERSION); } break; default: // @todo check version requirements for other db adapters $dbcheck = TRUE; break; } } catch (Zend_Db_Adapter_Exception $zae) { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' ' . $zae->getMessage()); } catch (Zend_Db_Exception $zde) { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' ' . $zde->getMessage()); } } self::set(Setup_Core::CHECKDB, $dbcheck); return $dbcheck; }
/** * clear the cache */ protected function _clearCache() { if (Setup_Core::isLogLevel(Zend_Log::DEBUG)) { Setup_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' clearing cache ... '); } Tinebase_Core::getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('config')); }