/** * This is what Datamanager calls to actually create a person */ public function &dm2_create_callback(&$datamanager) { $person = new org_openpsa_contacts_person_dba(); if (!$person->create()) { debug_print_r('We operated on this object:', $person); throw new midcom_error("Failed to create a new person, cannot continue. Error: " . midcom_connection::get_error_string()); } $this->_person =& $person; return $person; }
public function testCRUD() { midcom::get('auth')->request_sudo('org.openpsa.contacts'); $person = new org_openpsa_contacts_person_dba(); $person->lastname = 'TEST PERSON ' . __CLASS__; $stat = $person->create(); $this->assertTrue($stat); $this->register_object($person); $this->assertEquals(org_openpsa_contacts_person_dba::TYPE_PERSON, $person->orgOpenpsaObtype); $this->assertEquals('rname', $person->get_label_property()); $person->firstname = 'FIRSTNAME'; $stat = $person->update(); $this->assertTrue($stat); $this->assertEquals('TEST PERSON ' . __CLASS__ . ', FIRSTNAME', $person->get_label()); $stat = $person->delete(); $this->assertTrue($stat); midcom::get('auth')->drop_sudo(); }
private function _import_subscribers_person($subscriber) { $person = null; if ($this->_config->get('csv_import_check_duplicates')) { if (array_key_exists('email', $subscriber['person']) && $subscriber['person']['email']) { // Perform a simple email test. More complicated duplicate checking is best left to the o.o.contacts duplicate checker $qb = org_openpsa_contacts_person_dba::new_query_builder(); $qb->add_constraint('email', '=', $subscriber['person']['email']); $persons = $qb->execute_unchecked(); if (count($persons) > 0) { // Match found, use it $person = $persons[0]; } } if (!$person && array_key_exists('handphone', $subscriber['person']) && $subscriber['person']['handphone']) { // Perform a simple cell phone test. More complicated duplicate checking is best left to the o.o.contacts duplicate checker $qb = org_openpsa_contacts_person_dba::new_query_builder(); $qb->add_constraint('handphone', '=', $subscriber['person']['handphone']); $persons = $qb->execute_unchecked(); if (count($persons) > 0) { // Match found, use it $person = $persons[0]; } } } if (!$person) { // We didn't have person matching the email in DB. Create a new one. $person = new org_openpsa_contacts_person_dba(); // Populate at least one field for the new person if (isset($subscriber['person']) && isset($subscriber['person']['email'])) { $person->email = $subscriber['person']['email']; } if (!$person->create()) { $this->_request_data['new_objects']['person'] =& $person; debug_add("Failed to create person, reason " . midcom_connection::get_error_string()); $this->_request_data['import_status']['failed_create']++; return false; // This will skip to next } } if (!$this->_datamanager_process('person', $subscriber, $person)) { return false; } return $person; }