Exemplo n.º 1
0
 public function testCRUD()
 {
     $time = time();
     midcom::get('auth')->request_sudo('org.openpsa.products');
     $group = new org_openpsa_products_product_group_dba();
     $group->code = 'TEST-100' . $time;
     $stat = $group->create();
     $this->assertTrue($stat);
     $this->assertEquals($group->code, 'TEST-100' . $time);
     $group->code = 'TEST-101' . $time;
     $stat = $group->update();
     $this->assertTrue($stat);
     $this->register_object($group);
     $this->assertEquals($group->code, 'TEST-101' . $time);
     $group2 = new org_openpsa_products_product_group_dba();
     $group2->code = 'TEST-101' . $time;
     $stat = $group2->create();
     $this->assertFalse($stat);
     $this->assertEquals(midcom_connection::get_error(), MGD_ERR_OBJECT_NAME_EXISTS);
     $stat = $group->delete();
     $this->assertTrue($stat);
     midcom::get('auth')->drop_sudo();
 }
Exemplo n.º 2
0
 private function _import_group($groupdata)
 {
     // Convert fields from latin-1 to MidCOM charset (usually utf-8)
     foreach ($groupdata as $key => $value) {
         $groupdata[$key] = iconv('ISO-8859-1', midcom::get('i18n')->get_current_charset(), $value);
     }
     $group = null;
     $new = false;
     if (isset($groupdata['code'])) {
         $qb = org_openpsa_products_product_group_dba::new_query_builder();
         $qb->add_constraint('code', '=', (string) $groupdata['code']);
         $groups = $qb->execute();
         if (count($groups) > 0) {
             // Match found, use it
             $group = $groups[0];
             $this->_request_data['import_status']['already_created']++;
         }
     }
     if (!$group) {
         // We didn't have group matching the code in DB. Create a new one.
         $group = new org_openpsa_products_product_group_dba();
         if (!$group->create()) {
             debug_add("Failed to create group, reason " . midcom_connection::get_error_string());
             $this->_request_data['import_status']['failed_create']++;
             return false;
             // This will skip to next
         }
         $new = true;
         $this->_request_data['import_status']['created_new']++;
     }
     if (isset($groupdata['org_openpsa_products_import_parent_group'])) {
         // Validate and set parent group
         $qb = org_openpsa_products_product_group_dba::new_query_builder();
         $qb->add_constraint('code', '=', (string) $groupdata['org_openpsa_products_import_parent_group']);
         $parents = $qb->execute();
         if (count($parents) == 0) {
             // Invalid parent, delete
             $group->delete();
             $this->_request_data['import_status']['failed_create']++;
             return false;
         }
         $group->up = $parents[0]->id;
         $groupdata['up'] = $parents[0]->id;
         $group->update();
     }
     if (!$this->_datamanager_process($groupdata, $group)) {
         if ($new) {
             $group->delete();
             $this->_request_data['import_status']['failed_create']++;
         }
         return false;
     }
     $this->_groups_processed[$group->code] = $group;
     return $group;
 }