/** * the constructor * */ private function __construct() { // set start date to start date of june 1st before last year $date = Tinebase_DateTime::now(); $this->_startDate = $date->setDate($date->format('Y') - 2, 6, 1); $this->_loadCostCentersAndDivisions(); }
/** * testNextScheduledImport */ public function testNextScheduledImport() { $cc = Calendar_Controller_Event::getInstance(); $filter = new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()))); $all = $cc->search($filter); $this->assertEquals(0, $all->count()); $now = Tinebase_DateTime::now()->subHour(1); $record = $this->createScheduledImport(); // assert setting timestamp to start value $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi')); $record = $this->_uit->runNextScheduledImport(); // assert updating timestamp after successful run $now->addHour(1); $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi')); $all = $cc->search($filter); $seq = $all->getFirstRecord()->seq; // assert all events have been imported $this->assertEquals(7, $all->count()); // this must not be run, the interval is not exceed $ret = $this->_uit->runNextScheduledImport(); $all = $cc->search($filter); $this->assertEquals($seq, $all->getFirstRecord()->seq); // setting manual timestamp to force run again $record->timestamp = $record->timestamp->subHour(1)->subSecond(1); $this->_uit->update($record); $ret = $this->_uit->runNextScheduledImport(); $all = $cc->search($filter); $this->assertEquals(7, $all->count()); }
protected function _onAfterExportRecords($result) { $user = Tinebase_Core::getUser(); $this->_docTemplate->setValue('date', Tinebase_DateTime::now()->format('Y-m-d')); $this->_docTemplate->setValue('account_n_given', $user->accountFirstName); $this->_docTemplate->setValue('account_n_family', $user->accountLastName); }
/** * test a whole call cycle - start, connect, disconnect * */ public function testWholeCall() { // start call $call = $this->_backend->callStarted($this->_objects['call']); $this->assertEquals($this->_objects['call']->destination, $call->destination); $this->assertTrue(Tinebase_DateTime::now()->sub($call->start)->getTimestamp() >= 0); // sleep for 2 secs (ringing...) sleep(2); // connect call $call = $this->_backend->getCall($this->_objects['call']->getId()); $ringing = $call->ringing; $connectedCall = $this->_backend->callConnected($call); $this->assertEquals($this->_objects['call']->destination, $connectedCall->destination); $this->assertEquals(-1, $call->start->compare($call->connected)); // sleep for 5 secs (talking...) sleep(5); // disconnect call $call = $this->_backend->getCall($this->_objects['call']->getId()); $duration = $call->duration; $disconnectedCall = $this->_backend->callDisconnected($call); $this->assertGreaterThan($duration, $disconnectedCall->duration); $this->assertLessThan(10, $disconnectedCall->ringing, 'wrong ringing duration'); $this->assertLessThan(15, $disconnectedCall->duration, 'wrong duration'); $this->assertEquals(-1, $disconnectedCall->connected->compare($disconnectedCall->disconnected)); }
/** * @see 0011156: big files can't be uploaded */ public function testCreateTempFileWithBigSize() { $size = (double) (3.8 * 1024.0 * 1024.0 * 1024.0); $tempFile = new Tinebase_Model_TempFile(array('id' => '123', 'session_id' => 'abc', 'time' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG), 'path' => '/tmp/tmpfile', 'name' => 'tmpfile', 'type' => 'unknown', 'error' => 0, 'size' => $size)); $createdTempFile = $this->_instance->create($tempFile); $this->assertEquals(4080218931.0, $createdTempFile->size); }
/** * Test create a access log and logout to set logout time * * @see 0010728: Strange error in tine20 log when performing logout from Web */ public function testSetLogout() { $accessLog = new Tinebase_Model_AccessLog(array('ip' => '127.0.0.1', 'li' => Tinebase_DateTime::now(), 'result' => Zend_Auth_Result::SUCCESS, 'clienttype' => 'unittest', 'login_name' => 'unittest', 'user_agent' => 'phpunit', 'sessionid' => Tinebase_Record_Abstract::generateUID()), true); $this->_uit->setSessionId($accessLog); $this->_uit->create($accessLog); $accessLog = $this->_uit->setLogout(); $this->assertEquals(Tinebase_DateTime::now()->toString(), $accessLog->lo->toString(), 'logout time mismatch/empty: ' . print_r($accessLog, true)); }
/** * delete user by id * * @param string $id */ protected function _deleteUserById($id) { $where = array($this->_db->quoteIdentifier($this->_propertyMapping['emailUserId']) . ' = ?' => $id, $this->_db->quoteIdentifier($this->_userTable . '.domain') . ' = ?' => $this->_config['domain']); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($where, TRUE)); } $this->_db->update($this->_userTable, array('is_deleted' => '1', 'last_modified' => Tinebase_DateTime::now()->getIso()), $where); }
/** * testBackslashInDescription * * @see 0009176: iCal adds another backslash to description field */ public function testBackslashInDescription() { $event = new Calendar_Model_Event(array('summary' => 'CalDAV test', 'dtstart' => Tinebase_DateTime::now(), 'dtend' => Tinebase_DateTime::now()->addHour(1), 'description' => 'lalala \\\\', 'originator_tz' => 'Europe/Berlin', 'creation_time' => Tinebase_DateTime::now(), 'uid' => Tinebase_Record_Abstract::generateUID(), 'seq' => 1)); $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_MACOSX); $vevent = $converter->fromTine20Model($event)->serialize(); $convertedEvent = $converter->toTine20Model($vevent); $this->assertEquals($event->description, $convertedEvent->description); }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { parent::setUp(); $this->_testContainer = $this->_getPersonalContainer('Crm'); $this->objects['lead'] = new Crm_Model_Lead(array('lead_name' => 'PHPUnit', 'leadstate_id' => 1, 'leadtype_id' => 1, 'leadsource_id' => 1, 'container_id' => $this->_testContainer->id, 'start' => new Tinebase_DateTime("2007-12-12"), 'description' => 'Lead Description', 'end' => Tinebase_DateTime::now(), 'turnover' => '200000', 'probability' => 70, 'end_scheduled' => Tinebase_DateTime::now())); $this->objects['leadWithLink'] = new Crm_Model_Lead(array('lead_name' => 'PHPUnit with contact', 'leadstate_id' => 1, 'leadtype_id' => 1, 'leadsource_id' => 1, 'container_id' => $this->_testContainer->id, 'start' => new Tinebase_DateTime("2007-12-24"), 'description' => 'Lead Description', 'end' => Tinebase_DateTime::now(), 'turnover' => '200000', 'probability' => 50, 'end_scheduled' => Tinebase_DateTime::now())); $this->objects['linkedContact'] = new Addressbook_Model_Contact(array('adr_one_countryname' => 'DE', 'adr_one_locality' => 'Hamburg', 'adr_one_postalcode' => '24xxx', 'adr_one_region' => 'Hamburg', 'adr_one_street' => 'Pickhuben 4', 'adr_one_street2' => 'no second street', 'adr_two_countryname' => 'DE', 'adr_two_locality' => 'Hamburg', 'adr_two_postalcode' => '24xxx', 'adr_two_region' => 'Hamburg', 'adr_two_street' => 'Pickhuben 4', 'adr_two_street2' => 'no second street2', 'assistent' => 'Cornelius Weiß', 'bday' => '1975-01-02 03:04:05', 'email' => '*****@*****.**', 'email_home' => '*****@*****.**', 'note' => 'Bla Bla Bla', 'role' => 'Role', 'title' => 'Title', 'url' => 'http://www.tine20.org', 'url_home' => 'http://www.tine20.com', 'n_family' => 'Kneschke', 'n_fileas' => 'Kneschke, Lars', 'n_given' => 'Lars', 'n_middle' => 'no middle name', 'n_prefix' => 'no prefix', 'n_suffix' => 'no suffix', 'org_name' => 'Metaways Infosystems GmbH', 'org_unit' => 'Tine 2.0', 'tel_assistent' => '+49TELASSISTENT', 'tel_car' => '+49TELCAR', 'tel_cell' => '+49TELCELL', 'tel_cell_private' => '+49TELCELLPRIVATE', 'tel_fax' => '+49TELFAX', 'tel_fax_home' => '+49TELFAXHOME', 'tel_home' => '+49TELHOME', 'tel_pager' => '+49TELPAGER', 'tel_work' => '+49TELWORK')); $this->objects['linkedTask'] = new Tasks_Model_Task(array('summary' => 'task test')); Crm_Controller_Lead::getInstance()->create($this->objects['leadWithLink']); $this->objects['linkedContact'] = Addressbook_Controller_Contact::getInstance()->create($this->objects['linkedContact'], FALSE); }
/** * Sets up the fixture. * * This method is called before a test is executed. */ protected function setUp() { $personalContainer = Tinebase_Container::getInstance()->getPersonalContainer(Zend_Registry::get('currentAccount'), 'Crm', Zend_Registry::get('currentAccount'), Tinebase_Model_Grants::GRANT_EDIT); if ($personalContainer->count() === 0) { $this->_testContainer = Tinebase_Container::getInstance()->addPersonalContainer(Zend_Registry::get('currentAccount')->accountId, 'Crm', 'PHPUNIT'); } else { $this->_testContainer = $personalContainer[0]; } $this->_objects['initialLead'] = new Crm_Model_Lead(array('id' => 120, 'lead_name' => 'PHPUnit', 'leadstate_id' => 1, 'leadtype_id' => 1, 'leadsource_id' => 1, 'container_id' => $this->_testContainer->id, 'start' => Tinebase_DateTime::now(), 'description' => 'Description', 'end' => Tinebase_DateTime::now(), 'turnover' => '200000', 'probability' => 70, 'end_scheduled' => Tinebase_DateTime::now())); $this->_objects['updatedLead'] = new Crm_Model_Lead(array('id' => 120, 'lead_name' => 'PHPUnit', 'leadstate_id' => 1, 'leadtype_id' => 1, 'leadsource_id' => 1, 'container_id' => $this->_testContainer->id, 'start' => Tinebase_DateTime::now(), 'description' => 'Description updated', 'end' => NULL, 'turnover' => '200000', 'probability' => 70, 'end_scheduled' => NULL)); $this->_backend = new Crm_Backend_Lead(); }
/** * Returns the last modification time * * @return int */ public function getLastModified() { if ($this->_node instanceof Tinebase_Model_Tree_Node) { if ($this->_node->last_modified_time instanceof Tinebase_DateTime) { $timestamp = $this->_node->last_modified_time->getTimestamp(); } else { $timestamp = $this->_node->creation_time->getTimestamp(); } } else { $timestamp = Tinebase_DateTime::now()->getTimestamp(); } return $timestamp; }
/** * testUpdateProductLifespan * * @see 0010766: set product lifespan */ public function testUpdateProductLifespan() { $product1 = $this->getUit()->create(new Sales_Model_Product(array('name' => 'product activates in future', 'lifespan_start' => Tinebase_DateTime::now()->addDay(1)))); $product2 = $this->getUit()->create(new Sales_Model_Product(array('name' => 'product lifespan ended', 'lifespan_end' => Tinebase_DateTime::now()->subDay(1)))); $product3 = $this->getUit()->create(new Sales_Model_Product(array('is_active' => 0, 'name' => 'product lifespan started', 'lifespan_start' => Tinebase_DateTime::now()->subDay(1)))); $product4 = $this->getUit()->create(new Sales_Model_Product(array('is_active' => 0, 'name' => 'product lifespan not yet ended', 'lifespan_end' => Tinebase_DateTime::now()->addDay(1)))); $productsToTest = array(array('expectedIsActive' => 0, 'product' => $product1), array('expectedIsActive' => 0, 'product' => $product2), array('expectedIsActive' => 1, 'product' => $product3), array('expectedIsActive' => 1, 'product' => $product4)); $this->getUit()->updateProductLifespan(); foreach ($productsToTest as $product) { $updatedProduct = $this->getUit()->get($product['product']); $this->assertEquals($product['expectedIsActive'], $updatedProduct->is_active, print_r($product['product']->toArray(), true)); } }
public function testCreateEvent() { $event = $this->_getEvent(); $event->creation_time = Tinebase_DateTime::now(); $persistentEvent = $this->_backend->create($event); $event->attendee->cal_event_id = $persistentEvent->getId(); foreach ($event->attendee as $attender) { $this->_backend->createAttendee($attender); } $loadedPersitentEvent = $this->_backend->get($persistentEvent->getId()); $this->assertEquals($event->summary, $loadedPersitentEvent->summary); $this->_assertAttendee($event->attendee, $loadedPersitentEvent->attendee); return $loadedPersitentEvent; }
/** * try to lock a folder * * @param Felamimail_Model_Folder $_folder the folder to lock * @return bool true if locking was successful, false if locking was not possible */ public function lockFolder(Felamimail_Model_Folder $_folder) { $folderData = $_folder->toArray(); $data = array('cache_timestamp' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG), 'cache_status' => Felamimail_Model_Folder::CACHE_STATUS_UPDATING); $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $folderData['id']), $this->_db->quoteInto($this->_db->quoteIdentifier('cache_status') . ' = ?', $folderData['cache_status'])); if (!empty($folderData['cache_timestamp'])) { $where[] = $this->_db->quoteInto($this->_db->quoteIdentifier('cache_timestamp') . ' = ?', $folderData['cache_timestamp']); } $affectedRows = $this->_db->update($this->_tablePrefix . $this->_tableName, $data, $where); if ($affectedRows !== 1) { return false; } return true; }
/** * add logout entry to the access log * * @param string $_sessionId the session id * @param string $_ipAddress the ip address the user connects from * @return void|Tinebase_Model_AccessLog */ public function setLogout($_sessionId, $_ipAddress = NULL) { try { $loginRecord = $this->_backend->getByProperty($_sessionId, 'sessionid'); } catch (Tinebase_Exception_NotFound $tenf) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not find access log login record for session id ' . $_sessionId); return; } $loginRecord->lo = Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG); if ($_ipAddress !== NULL) { $loginRecord->ip = $_ipAddress; } return $this->update($loginRecord); }
/** * test start * */ public function testStartCall() { // remove old call try { $call = $this->_backend->getCall($this->_objects['call']->getId()); $backend = Phone_Backend_Factory::factory(Phone_Backend_Factory::CALLHISTORY); $backend->delete($this->_objects['call']->getId()); } catch (Exception $e) { // do nothing } $call = $this->_backend->callStarted($this->_objects['call']); $this->assertEquals($this->_objects['call']->destination, $call->destination); $this->assertTrue(Tinebase_DateTime::now()->sub($call->start)->getTimestamp() >= 0); // sleep for 2 secs (ringing...) sleep(2); }
/** * Returns an array with all the child nodes * * @return Sabre_DAV_INode[] */ function getChildren() { $filterClass = $this->_application->name . '_Model_' . $this->_model . 'Filter'; $filter = new $filterClass(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_container->getId()), array('field' => 'period', 'operator' => 'within', 'value' => array('from' => Tinebase_DateTime::now()->subWeek(4), 'until' => Tinebase_DateTime::now()->addYear(4))))); /** * see http://forge.tine20.org/mantisbt/view.php?id=5122 * we must use action 'sync' and not 'get' as * otherwise the calendar also return events the user only can see because of freebusy */ $objects = $this->_getController()->search($filter, null, false, false, 'sync'); $children = array(); foreach ($objects as $object) { $children[] = $this->getChild($object); } return $children; }
/** * do the import */ public function import() { $this->_log->NOTICE(__METHOD__ . '::' . __LINE__ . ' starting egw import for Adressbook'); $this->_migrationStartTime = Tinebase_DateTime::now(); $this->_tineRecordBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL); $estimate = $this->_getEgwRecordEstimate(); $this->_log->NOTICE(__METHOD__ . '::' . __LINE__ . " found {$estimate} contacts for migration"); $pageSize = 100; $numPages = ceil($estimate / $pageSize); for ($page = 1; $page <= $numPages; $page++) { $this->_log->info(__METHOD__ . '::' . __LINE__ . " starting migration page {$page} of {$numPages}"); Tinebase_Core::setExecutionLifeTime($pageSize * 10); $recordPage = $this->_getRawEgwRecordPage($page, $pageSize); $this->_migrateEgwRecordPage($recordPage); } $this->_log->NOTICE(__METHOD__ . '::' . __LINE__ . ' ' . ($this->_importResult['totalcount'] - $this->_importResult['failcount']) . ' contacts imported sucessfully ' . ($this->_importResult['failcount'] ? " {$this->_importResult['failcount']} contacts skipped with failures" : "")); }
/** * import one purchase imvoice file * * a new invoice with default data will be created and the invoice file will be attached * * @param string $name name of the invoice * @param resource $data binary data of the invoice (aka a pdf) * @throws Sabre\DAV\Exception\Forbidden * @return Sales_Model_PurchaseInvoice */ public function importPurchaseInvoice($name, $data) { // create invoice $purchaseInvoice = new Sales_Model_PurchaseInvoice(array('number' => '', 'description' => '', 'date' => Tinebase_DateTime::now(), 'discount' => 0, 'due_in' => 0, 'due_at' => Tinebase_DateTime::now(), 'price_gross' => 0, 'price_net' => 0, 'price_tax' => 0, 'sales_tax' => 0)); $invoice = $this->create($purchaseInvoice); // attach invoice file (aka a pdf) $attachmentPath = Tinebase_FileSystem_RecordAttachments::getInstance()->getRecordAttachmentPath($purchaseInvoice, TRUE); $handle = Tinebase_FileSystem::getInstance()->fopen($attachmentPath . '/' . $name, 'w'); if (!is_resource($handle)) { throw new Sabre\DAV\Exception\Forbidden('Permission denied to create file:' . $attachmentPath . '/' . $name); } if (is_resource($data)) { stream_copy_to_stream($data, $handle); } Tinebase_FileSystem::getInstance()->fclose($handle); return $this->get($purchaseInvoice); }
/** * tests for the contract controller */ public function testUpdateContract() { $contractController = HumanResources_Controller_Contract::getInstance(); $employeeController = HumanResources_Controller_Employee::getInstance(); $contractBackend = new HumanResources_Backend_Contract(); $employee = $employeeController->create($this->_getEmployee('sclever')); $testDate = Tinebase_DateTime::now()->setDate(Tinebase_DateTime::now()->format('Y'), 5, 13); $inAMonth = clone $testDate; $inAMonth->addMonth(1); $threeHrAgo = clone $testDate; $threeHrAgo->subHour(3); $startDate1 = clone $testDate; $startDate1->subMonth(2); $startDate2 = clone $testDate; $startDate2->subMonth(1); $edate1 = clone $startDate2; $edate1->addYear(1); // contract1 in the past, but created a second ago $contract1 = $this->_getContract(); $contract1->employee_id = $employee->getId(); $contract1->start_date = $startDate1; $contract1->creation_time = $testDate; $contract1 = $contractBackend->create($contract1); $contract2 = $this->_getContract(); $contract2->employee_id = $employee->getId(); $contract2->start_date = $startDate2; $contract2->end_date = $edate1; $contract2 = $contractBackend->create($contract2); // account $accountInstance = HumanResources_Controller_Account::getInstance(); $accountInstance->createMissingAccounts(); $accountFilter = new HumanResources_Model_AccountFilter(array(array('field' => 'year', 'operator' => 'equals', 'value' => $testDate->format('Y')))); $accountFilter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'employee_id', 'operator' => 'equals', 'value' => $employee->getId()))); $myAccount = $accountInstance->search($accountFilter)->getFirstRecord(); $firstDayDate = clone $startDate2; $firstDayDate->addDay(3); $vacation = new HumanResources_Model_FreeTime(array('status' => 'ACCEPTED', 'employee_id' => $employee->getId(), 'account_id' => $myAccount->getId(), 'type' => 'vacation', 'freedays' => array(array('date' => $firstDayDate, 'duration' => 1)))); $vacation = HumanResources_Controller_FreeTime::getInstance()->create($vacation); $newCalendar = $this->_getFeastCalendar(true); // LAST ASSERTION, do not add assertions after an expected Exception, they won't be executed $this->setExpectedException('HumanResources_Exception_ContractNotEditable'); $contract2->feast_calendar_id = $newCalendar->getId(); $contract2 = $contractController->update($contract2); // no more assertions here! }
/** * set the password for given account * * @param int $_accountId * @param string $_password * @param bool $_encrypt encrypt password * @return void * @throws Tinebase_Exception_InvalidArgument */ public function setPassword($_loginName, $_password, $_encrypt = TRUE) { if (empty($_loginName)) { throw new Tinebase_Exception_InvalidArgument('$_loginName can not be empty'); } $user = $this->getFullUserByLoginName($_loginName); $metaData = $this->_getMetaData($user); $encryptionType = $this->_options['pwEncType']; $userpassword = $_encrypt ? Tinebase_User_Abstract::encryptPassword($_password, $encryptionType) : $_password; $ldapData = array('userpassword' => $userpassword, 'shadowlastchange' => Tinebase_DateTime::now()->getTimestamp()); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' $dn: ' . $metaData['dn']); } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' $ldapData: ' . print_r($ldapData, true)); } $this->_backend->update($metaData['dn'], $ldapData); }
protected function _createCalls() { $lineId = $this->_phone->lines[0]['id']; $phoneId = $this->_phone->getId(); $d1 = Tinebase_DateTime::now()->subDay()->setTime(12, 00, 00); $d2 = clone $d1; $d2->addSecond(10); $d3 = clone $d2; $d3->addMinute(20); $i = 1; while ($i < 20) { $call = array('line_id' => $lineId, 'phone_id' => $phoneId, 'callerid' => $i * 100, 'start' => $d1, 'connected' => $d2, 'disconnected' => $d3, 'duration' => $d3->getTimestamp() - $d2->getTimestamp(), 'ringing' => $i, 'direction' => $i % 2 ? 'in' : 'out', 'source' => '+49123456789', 'destination' => '+44' . $i . $i . $i . $i); Phone_Controller_Call::getInstance()->create(new Phone_Model_Call($call)); $d1->addMinute(20)->subSecond($i); $d2->addMinute(20)->addSecond($i); $d3->addMinute(20)->addSecond($i * 1); $i++; } }
/** * do the import */ public function import() { $this->_migrationStartTime = Tinebase_DateTime::now(); $this->_calEventBackend = new Calendar_Backend_Sql(); /* $tineDb = Tinebase_Core::getDb(); Tinebase_TransactionManager::getInstance()->startTransaction($tineDb); */ $estimate = $this->_getEgwEventsCount(); $this->_log->info("found {$estimate} events for migration"); $pageSize = 100; $numPages = ceil($estimate / $pageSize); for ($page = 1; $page <= $numPages; $page++) { $this->_log->info("starting migration page {$page} of {$numPages}"); // NOTE: recur events with lots of exceptions might consume LOTS of time! Tinebase_Core::setExecutionLifeTime($pageSize * 10); $eventPage = $this->_getRawEgwEventPage($page, $pageSize); $this->_migrateEventPage($eventPage); } }
/** * Sets up the fixture. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $GLOBALS['Crm_ControllerTest'] = isset($GLOBALS['Crm_ControllerTest']) || array_key_exists('Crm_ControllerTest', $GLOBALS) ? $GLOBALS['Crm_ControllerTest'] : array(); $personalContainer = Tinebase_Container::getInstance()->getPersonalContainer(Zend_Registry::get('currentAccount'), 'Crm', Zend_Registry::get('currentAccount'), Tinebase_Model_Grants::GRANT_EDIT); if ($personalContainer->count() === 0) { $this->_testContainer = Tinebase_Container::getInstance()->addPersonalContainer(Zend_Registry::get('currentAccount')->accountId, 'Crm', 'PHPUNIT'); } else { $this->_testContainer = $personalContainer[0]; } $this->_objects['initialLead'] = new Crm_Model_Lead(array('lead_name' => 'PHPUnit', 'leadstate_id' => 1, 'leadtype_id' => 1, 'leadsource_id' => 1, 'container_id' => $this->_testContainer->id, 'start' => Tinebase_DateTime::now(), 'description' => 'Description', 'end' => Tinebase_DateTime::now(), 'turnover' => '200000', 'probability' => 70, 'end_scheduled' => Tinebase_DateTime::now())); $this->_objects['updatedLead'] = new Crm_Model_Lead(array('lead_name' => 'PHPUnit', 'leadstate_id' => 1, 'leadtype_id' => 1, 'leadsource_id' => 1, 'container_id' => $this->_testContainer->id, 'start' => Tinebase_DateTime::now(), 'description' => 'Description updated', 'end' => NULL, 'turnover' => '200000', 'probability' => 70, 'end_scheduled' => NULL)); $addressbookPersonalContainer = Tinebase_Container::getInstance()->getPersonalContainer(Zend_Registry::get('currentAccount'), 'Addressbook', Zend_Registry::get('currentAccount'), Tinebase_Model_Grants::GRANT_EDIT); $addressbookContainer = $addressbookPersonalContainer[0]; $this->_objects['user'] = new Addressbook_Model_Contact(array('adr_one_countryname' => 'DE', 'adr_one_locality' => 'Hamburg', 'adr_one_postalcode' => '24xxx', 'adr_one_region' => 'Hamburg', 'adr_one_street' => 'Pickhuben 4', 'adr_one_street2' => 'no second street', 'adr_two_countryname' => 'DE', 'adr_two_locality' => 'Hamburg', 'adr_two_postalcode' => '24xxx', 'adr_two_region' => 'Hamburg', 'adr_two_street' => 'Pickhuben 4', 'adr_two_street2' => 'no second street2', 'assistent' => 'Cornelius Weiß', 'bday' => '1975-01-02 03:04:05', 'email' => '*****@*****.**', 'email_home' => '*****@*****.**', 'note' => 'Bla Bla Bla', 'container_id' => $addressbookContainer->id, 'role' => 'Role', 'title' => 'Title', 'url' => 'http://www.tine20.org', 'url_home' => 'http://www.tine20.com', 'n_family' => 'Kneschke', 'n_fileas' => 'Kneschke, Lars', 'n_given' => 'Lars', 'n_middle' => 'no middle name', 'n_prefix' => 'no prefix', 'n_suffix' => 'no suffix', 'org_name' => 'Metaways Infosystems GmbH', 'org_unit' => 'Tine 2.0', 'tel_assistent' => '+49TELASSISTENT', 'tel_car' => '+49TELCAR', 'tel_cell' => '+49TELCELL', 'tel_cell_private' => '+49TELCELLPRIVATE', 'tel_fax' => '+49TELFAX', 'tel_fax_home' => '+49TELFAXHOME', 'tel_home' => '+49TELHOME', 'tel_pager' => '+49TELPAGER', 'tel_work' => '+49TELWORK')); $tasksPersonalContainer = Tinebase_Container::getInstance()->getPersonalContainer(Zend_Registry::get('currentAccount'), 'Tasks', Zend_Registry::get('currentAccount'), Tinebase_Model_Grants::GRANT_EDIT); $tasksContainer = $tasksPersonalContainer[0]; // create test task $this->_objects['task'] = new Tasks_Model_Task(array('container_id' => $tasksContainer->id, 'created_by' => Zend_Registry::get('currentAccount')->getId(), 'creation_time' => Tinebase_DateTime::now(), 'percent' => 70, 'due' => Tinebase_DateTime::now()->addMonth(1), 'summary' => 'phpunit: crm test task')); $this->objects['note'] = new Tinebase_Model_Note(array('note_type_id' => 1, 'note' => 'phpunit test note')); }
/** * get next number identified by $model (e.g. Sales_Model_Contract) and update db * * @param string $model * @param integer $userId * @return integer * * @todo lock db */ public function getNext($model, $userId) { $queryResult = $this->_findNumberRecord($model); if (!$queryResult) { // find latest used number if there is already one or more numbers has been created manually $controller = Tinebase_Core::getApplicationInstance($model); $latestRecord = $controller->getAll('number', 'DESC')->getFirstRecord(); $nextNumber = $latestRecord ? intval($latestRecord->number) + 1 : 1; // create new number circle $number = new Sales_Model_Number(array('model' => $model, 'number' => $nextNumber, 'account_id' => $userId, 'update_time' => Tinebase_DateTime::now()), TRUE); $number = $this->create($number); } else { // increase and update $number = new Sales_Model_Number($queryResult); $number->number++; $number->account_id = $userId; $number->update_time = Tinebase_DateTime::now(); $number = $this->update($number); } return $number; }
/** * download file * * @param string $_path * * @todo allow to download a folder as ZIP file */ public function downloadFile($path) { $oldMaxExcecutionTime = Tinebase_Core::setExecutionLifeTime(0); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . ' Download file ' . $path); } $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath(Filemanager_Controller_Node::getInstance()->addBasePath($path)); $node = Filemanager_Controller_Node::getInstance()->getFileNode($pathRecord); // cache for 3600 seconds $maxAge = 3600; header('Cache-Control: private, max-age=' . $maxAge); header("Expires: " . gmdate('D, d M Y H:i:s', Tinebase_DateTime::now()->addSecond($maxAge)->getTimestamp()) . " GMT"); // overwrite Pragma header from session header("Pragma: cache"); header('Content-Disposition: attachment; filename="' . $node->name . '"'); header("Content-Type: " . $node->contenttype); $handle = fopen($pathRecord->streamwrapperpath, 'r'); fpassthru($handle); fclose($handle); Tinebase_Core::setExecutionLifeTime($oldMaxExcecutionTime); exit; }
/** * get next number identified by $_type (i.e. contract) and update db * * @param string $_type * @param integer $_userId * @return integer * * @todo lock db */ public function getNext($_type, $_userId) { // get number for type $select = $this->_getSelect(); $select->where($this->_db->quoteIdentifier('type') . ' = ?', $_type); $stmt = $this->_db->query($select); $queryResult = $stmt->fetch(); $stmt->closeCursor(); if (!$queryResult) { // create new number circle $number = new Sales_Model_Number(array('type' => $_type, 'number' => 1, 'account_id' => $_userId, 'update_time' => Tinebase_DateTime::now()), TRUE); $number = $this->create($number); } else { // increase and update $number = new Sales_Model_Number($queryResult); $number->number++; $number->account_id = $_userId; $number->update_time = Tinebase_DateTime::now(); $number = $this->update($number); } return $number; }
/** * cleanup old sessions files => needed only for filesystems based sessions */ public function cleanupSessions() { $config = Tinebase_Core::getConfig(); $backendType = $config->session && $config->session->backend ? ucfirst($config->session->backend) : 'File'; if (strtolower($backendType) == 'file') { $maxLifeTime = $config->session && $config->session->lifetime ? $config->session->lifetime : 86400; $path = Tinebase_Session_Abstract::getSessionDir(); $unlinked = 0; try { $dir = new DirectoryIterator($path); } catch (Exception $e) { if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " Could not cleanup sessions"); } Tinebase_Exception::log($e); return; } foreach ($dir as $fileinfo) { if (!$fileinfo->isDot() && !$fileinfo->isLink() && $fileinfo->isFile()) { if ($fileinfo->getMTime() < Tinebase_DateTime::now()->getTimestamp() - $maxLifeTime) { unlink($fileinfo->getPathname()); $unlinked++; } } } if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Deleted {$unlinked} expired session files"); } Tinebase_Config::getInstance()->set(Tinebase_Config::LAST_SESSIONS_CLEANUP_RUN, Tinebase_DateTime::now()->toString()); } }
/** * update call, set duration and ringing time * * @param Phone_Model_Call $_call * @return Phone_Model_Call */ public function callDisconnected(Phone_Model_Call $_call) { $backend = Phone_Backend_Factory::factory(Phone_Backend_Factory::CALLHISTORY); $_call->disconnected = Tinebase_DateTime::now(); $call = $backend->update($_call); // calculate duration and ringing time if ($call->connected instanceof DateTime) { // how long did we talk $connected = clone $call->connected; $disconnected = clone $call->disconnected; $call->duration = $disconnected->getTimestamp() - $connected->getTimestamp(); // how long was the telephone ringing $start = clone $call->start; $connected = clone $call->connected; $call->ringing = $connected->getTimestamp() - $start->getTimestamp(); } else { $start = clone $call->start; $disconnected = clone $call->disconnected; $call->ringing = $disconnected->getTimestamp() - $start->getTimestamp(); } $call = $backend->update($call); return $call; }
/** * test credential cache cleanup */ public function testClearCredentialCacheTable() { // add dummy record to credential cache $id = Tinebase_Record_Abstract::generateUID(); $db = Tinebase_Core::getDb(); $oneMinuteAgo = Tinebase_DateTime::now()->subMinute(1)->format(Tinebase_Record_Abstract::ISO8601LONG); $data = array('id' => $id, 'cache' => Tinebase_Record_Abstract::generateUID(), 'creation_time' => $oneMinuteAgo, 'valid_until' => $oneMinuteAgo); $table = SQL_TABLE_PREFIX . 'credential_cache'; Tinebase_Core::getDb()->insert($table, $data); Tinebase_Auth_CredentialCache::getInstance()->clearCacheTable(); $result = $db->fetchCol('SELECT id FROM ' . $db->quoteIdentifier($table) . ' WHERE ' . $db->quoteInto($db->quoteIdentifier('valid_until') . ' < ?', Tinebase_DateTime::now()->format(Tinebase_Record_Abstract::ISO8601LONG))); $this->assertNotContains($id, $result); }