/** * (non-PHPdoc) * @see Tinebase_Server_Interface::handle() */ public function handle(\Zend\Http\Request $request = null, $body = null) { $method = $this->getRequestMethod(); if (!in_array($method, array('Tinebase.monitoringCheckDB', 'Tinebase.monitoringCheckConfig'))) { Tinebase_Core::initFramework(); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Is cli request. method: ' . $method); } } // prevents problems with missing request uri (@see Sabre\HTTP\Request->getUri()) if (!isset($_SERVER['REQUEST_URI'])) { $_SERVER['REQUEST_URI'] = ''; } $tinebaseServer = new Tinebase_Frontend_Cli(); $opts = Tinebase_Core::get('opts'); if (!in_array($method, self::getAnonymousMethods($method))) { $tinebaseServer->authenticate($opts->username, $opts->password); } $result = $tinebaseServer->handle($opts); //@todo remove cli session path // convert function result to shell return code if ($result === NULL || $result === TRUE || !is_int($result)) { $result = 0; } else { if ($result === FALSE) { $result = 1; } } // finish profiling here - we won't run in Tinebase_Core again Tinebase_Core::finishProfiling(); Tinebase_Core::getDbProfiling(); exit($result); }
/** * handler for command line scripts * * @return boolean */ public function handle() { $opts = Tinebase_Core::get('opts'); if (!in_array($opts->method, array('Tinebase.monitoringCheckDB', 'Tinebase.monitoringCheckConfig'))) { $this->_initFramework(); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Is cli request. method: ' . (isset($opts->method) ? $opts->method : 'EMPTY')); } } $tinebaseServer = new Tinebase_Frontend_Cli(); if (!in_array($opts->method, array('Tinebase.triggerAsyncEvents', 'Tinebase.processQueue', 'Tinebase.monitoringCheckDB', 'Tinebase.monitoringCheckConfig', 'Tinebase.monitoringCheckCron', 'Tinebase.monitoringLoginNumber'))) { $tinebaseServer->authenticate($opts->username, $opts->password); } $result = $tinebaseServer->handle($opts); //@todo remove cli session path return $result; }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { parent::setUp(); $fe = new Tinebase_Frontend_Cli(); $opts = new Zend_Console_Getopt('abp:'); $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/tine20/tine20/HumanResources/Export/definitions/hr_default_ods.xml'; $opts->setArguments(array($path)); ob_start(); $fe->updateImportExportDefinition($opts); $output = ob_get_clean(); $this->assertContains('hr_default_ods.xml successfully.', $output); $filter = new Tinebase_Model_ImportExportDefinitionFilter(array(array('field' => 'name', 'operator' => 'equals', 'value' => 'hr_default_ods'))); $backend = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_ImportExportDefinition', 'tableName' => 'importexport_definition'), NULL); $this->_importDefinition = $backend->search($filter)->getFirstRecord(); $filter = new HumanResources_Model_EmployeeFilter(array()); $options = array('definitionId' => $this->_importDefinition->getId()); $this->_instance = Tinebase_Export::factory($filter, $options); }
/** * testMonitoringActiveUsers * * TODO generalize monitoring tests */ public function testMonitoringActiveUsers() { ob_start(); $result = $this->_cli->monitoringActiveUsers(); $out = ob_get_clean(); $this->assertEquals(0, $result); preg_match('/ACTIVE USERS OK \\| count=(\\d+);;;;/', $out, $matches); $this->assertGreaterThan(1, count($matches)); $this->assertGreaterThanOrEqual(1, $matches[1], 'at least unittest user should have logged in once'); }
/** * testMonitoringLoginNumber */ public function testMonitoringLoginNumber() { ob_start(); $result = $this->_cli->monitoringLoginNumber(); $out = ob_get_clean(); $this->assertEquals(0, $result); preg_match('/LOGINS OK \\| count=(\\d+);;;;/', $out, $matches); $this->assertGreaterThan(1, count($matches)); $this->assertGreaterThanOrEqual(0, $matches[1]); }
/** * tests demo data creation for all applications having demodata prepared */ public function testCreateAllDemoData() { $adbController = Addressbook_Controller_Contact::getInstance(); $normalContactsFilter = new Addressbook_Model_ContactFilter(array(array('field' => 'type', 'operator' => 'not', 'value' => 'user'))); $existingContacts = $adbController->search($normalContactsFilter); // skip admin as it will be called before all tests $opts = new Zend_Console_Getopt('abp:', array('skipAdmin')); ob_start(); $this->_cli->createAllDemoData($opts); ob_end_clean(); // test addressbook contacts / admin user contacts $accountContactsFilter = new Addressbook_Model_ContactFilter(array(array('field' => 'type', 'operator' => 'equals', 'value' => 'user'))); $normalContactsFilter = new Addressbook_Model_ContactFilter(array(array('field' => 'type', 'operator' => 'equals', 'value' => 'contact'))); $normalContacts = $adbController->search($normalContactsFilter); $accountContacts = $adbController->search($accountContactsFilter); // shared should be 700 $this->assertEquals(700 + $existingContacts->count(), $normalContacts->count(), 'NormalContacts'); // internal contacts/accounts $this->assertEquals(6, $accountContacts->count(), 'AccountContacts'); // test calendar entries $calController = Calendar_Controller_Event::getInstance(); $allEventsFilter = new Calendar_Model_EventFilter(array()); $allEvents = $calController->search($allEventsFilter); $this->assertEquals(49, $allEvents->count(), 'Events'); // test crm leads $crmController = Crm_Controller_Lead::getInstance(); $allLeadsFilter = new Crm_Model_LeadFilter(array()); $allLeads = $crmController->search($allLeadsFilter); $this->assertEquals(1, $allLeads->count(), 'One shared lead should have been found'); // test human resources $employeeController = HumanResources_Controller_Employee::getInstance(); $allEmployeesFilter = new HumanResources_Model_EmployeeFilter(array()); $allEmployees = $employeeController->search($allEmployeesFilter); $this->assertEquals(6, $allEmployees->count()); // remove employees again $employeeController->delete($allEmployees->id); }
/** * reinstall applications * and reset Demodata * php setup.php --reset_demodata USERNAME * * @param Zend_Console_Getopt $_opts */ protected function _resetDemodata(Zend_Console_Getopt $_opts) { $controller = Setup_Controller::getInstance(); $userController = Admin_Controller_User::getInstance(); $containerController = Tinebase_Container::getInstance(); $cli = new Tinebase_Frontend_Cli(); //Don't reset this applications $fixedApplications = array('Tinebase', 'Admin', 'Addressbook'); //Log in $opts = $_opts->getRemainingArgs(); $username = $opts[0]; if (empty($username)) { echo "Username is missing!\n"; exit; } $user = Tinebase_User::getInstance()->getUserByLoginName($username); Tinebase_Core::set(Tinebase_Core::USER, $user); //get all applications and remove some $applications = Tinebase_Application::getInstance()->getApplications(NULL, 'id'); foreach ($applications as $key => &$application) { if (in_array($application, $fixedApplications)) { unset($applications[$key]); } } //get set rights $users = Tinebase_Acl_Roles::getInstance()->getRoleByName('user role'); $rights = Tinebase_Acl_Roles::getInstance()->getRoleRights($users->getId()); //Uninstall Applications try { $controller->uninstallApplications($applications->name); echo "Successfully uninstalled " . count($applications) . " applications.\n"; } catch (Tinebase_Exception_NotFound $e) { } //Install Applications try { $controller->installApplications($applications->name); echo "Successfully installed " . count($applications) . " applications.\n"; } catch (Tinebase_Exception_NotFound $e) { } //set rights foreach ($applications as &$application) { $newApplicationId = Tinebase_Application::getInstance()->getApplicationByName($application->name)->getId(); foreach ($rights as &$right) { if ($right['application_id'] == $application->id) { $right['application_id'] = $newApplicationId; } } } Tinebase_Acl_Roles::getInstance()->setRoleRights($users->getId(), $rights); echo "Successfully restored user rights.\n"; //Clean up addressbooks $internalContacts = $userController->getDefaultInternalAddressbook(); $containers = $containerController->getAll(); foreach ($containers as $key => &$container) { if ($container->id == $internalContacts) { // Do nothing } else { try { $containerController->deleteContainer($container, true); } catch (Tinebase_Exception_NotFound $e) { } } } echo "Successfully cleand up containers.\n"; //remove state $db = Tinebase_Core::getDb(); $statement = "TRUNCATE TABLE " . $db->quoteIdentifier(SQL_TABLE_PREFIX . 'state'); $db->query($statement); echo "Successfully truncated state table.\n"; //Get Demodata $cli->createAllDemoData(); //clear Cache Tinebase_Core::getCache()->clean(Zend_Cache::CLEANING_MODE_ALL); echo "Successfully cleared Cache.\n"; echo "Every thing done!\n"; }