예제 #1
0
파일: create.php 프로젝트: nemein/openpsa
 /**
  * DM2 creation callback.
  */
 function &dm2_create_callback(&$controller)
 {
     // Create a new group
     $this->_group = new midcom_db_group();
     if (!$this->_group->create()) {
         debug_print_r('We operated on this object:', $this->_group);
         throw new midcom_error('Failed to create a new group. Last Midgard error was: ' . midcom_connection::get_error_string());
     }
     return $this->_group;
 }
예제 #2
0
 /**
  * Locates the root group
  */
 static function find_root_group($name = '__org_openpsa_contacts')
 {
     static $root_groups = array();
     //Check if we have already initialized
     if (!empty($root_groups[$name])) {
         return $root_groups[$name];
     }
     $qb = midcom_db_group::new_query_builder();
     $qb->add_constraint('owner', '=', 0);
     $qb->add_constraint('name', '=', $name);
     $results = $qb->execute();
     if (is_array($results) && count($results) > 0) {
         foreach ($results as $group) {
             $root_groups[$name] = $group;
         }
     } else {
         debug_add("OpenPSA Contacts root group could not be found", MIDCOM_LOG_WARN);
         //Attempt to  auto-initialize the group.
         midcom::get('auth')->request_sudo();
         $grp = new midcom_db_group();
         $grp->owner = 0;
         $grp->name = $name;
         $grp->official = midcom::get('i18n')->get_l10n('org.openpsa.contacts')->get($name);
         $ret = $grp->create();
         midcom::get('auth')->drop_sudo();
         if (!$ret) {
             throw new midcom_error("Could not auto-initialize the module, group creation failed: " . midcom_connection::get_error_string());
         }
         $root_groups[$name] = $grp;
     }
     return $root_groups[$name];
 }
예제 #3
0
 public function testCRUD()
 {
     midcom::get('auth')->request_sudo('midcom.core');
     $group = new midcom_db_group();
     $stat = $group->create();
     $this->assertTrue($stat);
     $this->register_object($group);
     $group->refresh();
     $this->assertEquals('Group #' . $group->id, $group->official);
     $this->assertEquals('Group #' . $group->id, $group->get_label());
     $group->official = 'TEST GROUP ' . __CLASS__;
     $stat = $group->update();
     $this->assertTrue($stat);
     $this->assertEquals('TEST GROUP ' . __CLASS__, $group->get_label());
     $stat = $group->delete();
     $this->assertTrue($stat);
     midcom::get('auth')->drop_sudo();
 }