/** * replaces all relations to or from a record with $sourceId to a record with $destinationId * * @param string $sourceId * @param string $destinationId * @param string $model * * @return array */ public function transferRelations($sourceId, $destinationId, $model) { if (!Tinebase_Core::getUser()->hasRight('Tinebase', Tinebase_Acl_Rights::ADMIN)) { throw new Tinebase_Exception_AccessDenied('Non admins of Tinebase aren\'t allowed to perform his operation!'); } return $this->_backend->transferRelations($sourceId, $destinationId, $model); }
/** * testBreakAllRelations */ public function testBreakAllRelations() { $rel = $this->relations[0]; $this->object->breakAllRelations($rel->own_model, $rel->own_backend, $rel->own_id); $relations = $this->object->getAllRelations($rel->own_model, $rel->own_backend, $rel->own_id); $this->assertEquals(0, count($relations)); // test that the other relations still exists $rel = $this->relations[2]; $this->object->getRelation($rel->getId(), $rel->related_model, $rel->related_backend, $rel->related_id); }
public function testCleanUp() { $backend = new Tinebase_Relation_Backend_Sql(); $backend->purgeAllRelations($this->_crmId['model'], $this->_crmId['backend'], $this->_crmId['id']); $backend->purgeAllRelations($this->_crmId2['model'], $this->_crmId2['backend'], $this->_crmId2['id']); }
/** * try to create a pdf with a linked task * */ public function testLeadPdfLinkedTask() { // create lead + task + link $task = Tasks_Controller_Task::getInstance()->create($this->objects['linkedTask']); $lead = Crm_Controller_Lead::getInstance()->get($this->objects['leadWithLink']->getId()); $lead->relations = array(array('own_model' => 'Crm_Model_Lead', 'own_backend' => 'Sql', 'own_id' => $lead->getId(), 'own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_model' => 'Tasks_Model_Task', 'related_backend' => Tasks_Backend_Factory::SQL, 'related_id' => $task->getId(), 'type' => 'TASK')); $lead = Crm_Controller_Lead::getInstance()->update($lead); $pdf = new Crm_Export_Pdf(); $pdf->generate($lead); $pdfOutput = $pdf->render(); //$pdf->save("test.pdf"); $this->assertEquals(1, preg_match("/^%PDF-1.4/", $pdfOutput), "no pdf generated"); $this->assertEquals(1, preg_match("/" . $task->summary . "/", $pdfOutput), "no summary found"); // remove Tasks_Controller_Task::getInstance()->delete($task->getId()); // purge all relations $backend = new Tinebase_Relation_Backend_Sql(); $backend->purgeAllRelations('Crm_Model_Lead', 'Sql', $this->objects['leadWithLink']->getId()); }
/** * update to 0.10 * - migrate old links to relations * */ public function update_9() { /************* migrate old links to relations *************/ // get all links $linksTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'links')); echo "fetching links ... <br/>\n"; $links = $linksTable->fetchAll(); // create relations from links $relationsByLeadId = array(); foreach ($links as $link) { if ($link->link_app1 === 'crm') { switch (strtolower($link->link_app2)) { case 'tasks': $relatedModel = 'Tasks_Model_Task'; $backend = Tasks_Backend_Factory::SQL; $degree = Tinebase_Model_Relation::DEGREE_SIBLING; $type = 'TASK'; break; case 'addressbook': $relatedModel = 'Addressbook_Model_Contact'; $backend = Addressbook_Backend_Factory::SQL; switch ($link->link_remark) { case 'account': $type = 'RESPONSIBLE'; $degree = Tinebase_Model_Relation::DEGREE_CHILD; break; case 'customer': $type = 'CUSTOMER'; $degree = Tinebase_Model_Relation::DEGREE_SIBLING; break; case 'partner': $type = 'PARTNER'; $degree = Tinebase_Model_Relation::DEGREE_SIBLING; break; } break; default: echo 'link type (' . $link->link_app2 . ") not supported<br/>\n"; } if (isset($relatedModel) && isset($backend)) { $relationsByLeadId[$link->link_id1][] = new Tinebase_Model_Relation(array('own_model' => 'Crm_Model_Lead', 'own_backend' => 'SQL', 'own_id' => $link->link_id1, 'related_degree' => $degree, 'related_model' => $relatedModel, 'related_backend' => $backend, 'related_id' => $link->link_id2, 'type' => $type, 'created_by' => $link->link_owner, 'creation_time' => Tinebase_DateTime::now())); } } } echo "creating relations ...<br/>\n"; $relationsBackend = new Tinebase_Relation_Backend_Sql(); foreach ($relationsByLeadId as $leadId => $relations) { foreach ($relations as $relation) { try { echo "set relation: " . $relation->type . " " . $relation->related_model . "<br/>\n"; $relationsBackend->addRelation($relation); } catch (Exception $e) { // cweiss 2008-08-25 this duplicates come from an earlier upgrading failure don't confuse user with verbosity ;-) // echo 'do not add duplicate relation ' . $relation->own_id . '-' . $relation->related_id . "...<br/>\n"; } } } echo "done<br/>\n"; $this->setApplicationVersion('Tinebase', '0.10'); }
/** * - use relations to save lead products * - remove old crm products tables * * @return void */ public function update_2() { if (Setup_Controller::getInstance()->isInstalled('Crm')) { // get linked products $select = $this->_db->select()->from(SQL_TABLE_PREFIX . 'metacrm_leads_products'); $stmt = $this->_db->query($select); $queryResult = $stmt->fetchAll(); //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . print_r($queryResult, TRUE)); // insert values into relations table $relationsBackend = new Tinebase_Relation_Backend_Sql(); foreach ($queryResult as $row) { $relation = new Tinebase_Model_Relation(array('own_model' => 'Crm_Model_Lead', 'own_backend' => 'Sql', 'own_id' => $row['lead_id'], 'own_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'type' => 'PRODUCT', 'related_model' => 'Sales_Model_Product', 'related_backend' => 'Sql', 'related_id' => $row['product_id'], 'remark' => Zend_Json::encode(array('description' => $row['product_desc'], 'price' => $row['product_price'], 'quantity' => 1)))); try { $relationsBackend->addRelation($relation); } catch (Zend_Db_Statement_Exception $zdse) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Found duplicate, increasing quantity (' . $zdse->getMessage() . ')'); // increase quantity $updateRelation = $relationsBackend->search(new Tinebase_Model_RelationFilter(array(array('field' => 'own_id', 'operator' => 'equals', 'value' => $relation->own_id), array('field' => 'related_id', 'operator' => 'equals', 'value' => $relation->related_id), array('field' => 'related_model', 'operator' => 'equals', 'value' => 'Sales_Model_Product'))))->getFirstRecord(); $remark = $updateRelation->remark; $remark['quantity'] = $remark['quantity'] + 1; $updateRelation->remark = $remark; //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($updateRelation->toArray(), TRUE)); $relationsBackend->updateRelation($updateRelation); } } // drop table metacrm_leadsproducts and metacrm_products $this->dropTable('metacrm_leads_products'); $this->dropTable('metacrm_products'); } $this->setApplicationVersion('Sales', '2.3'); }
/** * try to delete a lead * */ public function testDeleteLead() { Crm_Controller_Lead::getInstance()->delete($GLOBALS['Addressbook_ControllerTest']['leadId']); // purge all relations $backend = new Tinebase_Relation_Backend_Sql(); $backend->purgeAllRelations('Crm_Model_Lead', 'Sql', $GLOBALS['Addressbook_ControllerTest']['leadId']); // delete contact Addressbook_Controller_Contact::getInstance()->delete($this->_objects['user']->getId()); $this->setExpectedException('Tinebase_Exception_NotFound'); Crm_Controller_Lead::getInstance()->get($GLOBALS['Addressbook_ControllerTest']['leadId']); }
/** * remove all relations for application * * @param string $applicationName * * @return void */ public function removeApplication($applicationName) { $this->_backend->removeApplication($applicationName); }
/** * start phone call and save in history * * @param Phone_Model_Call $_call * @return Phone_Model_Call */ public function callStarted(Phone_Model_Call $_call) { $backend = Phone_Backend_Factory::factory(Phone_Backend_Factory::CALLHISTORY); $_call->start = Tinebase_DateTime::now(); $filter = new Voipmanager_Model_Asterisk_SipPeerFilter(array(array('field' => 'name', 'operator' => 'equals', 'value' => $_call->line_id))); $asteriskSipPeers = Voipmanager_Controller_Asterisk_SipPeer::getInstance()->search($filter); if (count($asteriskSipPeers) > 0) { $_call->callerid = $asteriskSipPeers[0]->callerid; } else { $_call->callerid = $_call->line_id; } $call = $backend->create($_call); // resolve telephone number to contacts if possible $phoneController = Phone_Controller_Call::getInstance(); $telNumber = Addressbook_Model_Contact::normalizeTelephoneNoCountry($phoneController->resolveInternalNumber($call->destination)); if (null !== $telNumber) { $filter = new Addressbook_Model_ContactFilter(array(array('field' => 'telephone_normalized', 'operator' => 'equals', 'value' => $telNumber))); $controller = Addressbook_Controller_Contact::getInstance(); $oldAclChecks = $controller->doContainerACLChecks(); $controller->doContainerACLChecks(false); $contacts = $controller->search($filter); $relationBackend = new Tinebase_Relation_Backend_Sql(); foreach ($contacts as $contact) { // we dont add the relations to the call record as this is called by the phone server, so no need to return the relations $relationBackend->addRelation(new Tinebase_Model_Relation(array('own_model' => 'Phone_Model_Call', 'own_id' => $call->getId(), 'own_backend' => Tinebase_Model_Relation::DEFAULT_RECORD_BACKEND, 'related_model' => 'Addressbook_Model_Contact', 'related_id' => $contact->getId(), 'related_degree' => Tinebase_Model_Relation::DEGREE_SIBLING, 'related_backend' => Tinebase_Model_Relation::DEFAULT_RECORD_BACKEND, 'type' => 'CALLER'))); } $controller->doContainerACLChecks($oldAclChecks); } return $call; }
/** * update an existing relation * * @param Tinebase_Model_Relation $_relation * @return Tinebase_Model_Relation the updated relation */ protected function _updateRelation($_relation) { $_relation->last_modified_by = Tinebase_Core::getUser()->getId(); $_relation->last_modified_time = Tinebase_DateTime::now(); return $this->_backend->updateRelation($_relation); }