public function setUp()
 {
     parent::setUp();
     if (!self::$initialized) {
         $found = false;
         foreach (self::$DI['record_2']->get_databox()->get_meta_structure()->get_elements() as $field) {
             if (!$field->isBusiness()) {
                 continue;
             }
             $found = true;
         }
         if (!$found) {
             $field = \databox_field::create(self::$DI['app'], self::$DI['record_2']->get_databox(), 'testBusiness' . mt_rand(), false);
             $field->set_business(true);
             $field->save();
         }
         foreach (self::$DI['app']['phraseanet.appbox']->get_databoxes() as $databox) {
             break;
         }
     }
     $this->initialize();
     if (!self::$searchEngine instanceof SearchEngineInterface) {
         $this->markTestSkipped('Unable to initialize search Engine');
     }
     $options = new SearchEngineOptions();
     $options->onCollections($databox->get_collections());
     $this->options = $options;
 }
Пример #2
0
 public function setUp()
 {
     parent::setUp();
     $this->databox = self::$DI['record_1']->get_databox();
     $this->name_mono = 'Field Test Mono';
     $this->name_multi = 'Field Test Multi';
     $this->object_mono = $this->databox->get_meta_structure()->get_element_by_name($this->name_mono);
     $this->object_multi = $this->databox->get_meta_structure()->get_element_by_name($this->name_multi);
     if (!$this->object_mono instanceof databox_field) {
         $this->object_mono = databox_field::create(self::$DI['app'], $this->databox, $this->name_mono, false);
     }
     if (!$this->object_multi instanceof databox_field) {
         $this->object_multi = databox_field::create(self::$DI['app'], $this->databox, $this->name_multi, true);
     }
 }
Пример #3
0
 public function feed_meta_fields()
 {
     $sxe = $this->get_sxml_structure();
     foreach ($sxe->description->children() as $fname => $field) {
         $dom_struct = $this->get_dom_structure();
         $xp_struct = $this->get_xpath_structure();
         $fname = (string) $fname;
         $src = trim(isset($field['src']) ? str_replace('/rdf:RDF/rdf:Description/', '', $field['src']) : '');
         $meta_id = isset($field['meta_id']) ? $field['meta_id'] : null;
         if (!is_null($meta_id)) {
             continue;
         }
         $nodes = $xp_struct->query('/record/description/' . $fname);
         if ($nodes->length > 0) {
             $nodes->item(0)->parentNode->removeChild($nodes->item(0));
         }
         $this->saveStructure($dom_struct);
         $type = isset($field['type']) ? $field['type'] : 'string';
         $type = in_array($type, [databox_field::TYPE_DATE, databox_field::TYPE_NUMBER, databox_field::TYPE_STRING, databox_field::TYPE_TEXT]) ? $type : databox_field::TYPE_STRING;
         $multi = isset($field['multi']) ? (bool) (string) $field['multi'] : false;
         $meta_struct_field = databox_field::create($this->app, $this, $fname, $multi);
         $meta_struct_field->set_readonly(isset($field['readonly']) ? (string) $field['readonly'] : 0)->set_indexable(isset($field['index']) ? (string) $field['index'] : '1')->set_separator(isset($field['separator']) ? (string) $field['separator'] : '')->set_required(isset($field['required']) && (string) $field['required'] == 1)->set_business(isset($field['business']) && (string) $field['business'] == 1)->set_type($type)->set_tbranch(isset($field['tbranch']) ? (string) $field['tbranch'] : '')->set_thumbtitle(isset($field['thumbtitle']) ? (string) $field['thumbtitle'] : (isset($field['thumbTitle']) ? $field['thumbTitle'] : '0'))->set_report(isset($field['report']) ? (string) $field['report'] : '1')->save();
         try {
             $meta_struct_field->set_tag(\databox_field::loadClassFromTagName($src))->save();
         } catch (\Exception $e) {
         }
     }
     return $this;
 }
Пример #4
0
 public function testDeleteField()
 {
     $app = $this->getApplication();
     $databox = $this->getFirstDatabox($app);
     $field = \databox_field::create($app, $databox, 'testfield' . mt_rand(), false);
     $fieldId = $field->get_id();
     $data = $field->toArray();
     $data['business'] = true;
     $data['vocabulary-type'] = 'User';
     /** @var Client $client */
     $client = self::$DI['client'];
     $client->request("DELETE", sprintf("/admin/fields/%d/fields/%d", $databox->get_sbas_id(), $field->get_id()), [], [], [], json_encode($data));
     $response = $client->getResponse()->getContent();
     $this->assertEquals('', $response);
     $this->assertEquals(204, $client->getResponse()->getStatusCode());
     try {
         $databox->get_meta_structure()->get_element($fieldId);
         $this->fail('Should have raise an exception');
     } catch (\Exception $e) {
     }
 }
Пример #5
0
 public function testDeleteField()
 {
     $databoxes = self::$DI['app']['phraseanet.appbox']->get_databoxes();
     $databox = array_shift($databoxes);
     $field = \databox_field::create(self::$DI['app'], $databox, 'testfield' . mt_rand(), false);
     $fieldId = $field->get_id();
     $data = $field->toArray();
     $data['business'] = true;
     $data['vocabulary-type'] = 'User';
     self::$DI['client']->request("DELETE", sprintf("/admin/fields/%d/fields/%d", $databox->get_sbas_id(), $field->get_id()), [], [], [], json_encode($data));
     $response = self::$DI['client']->getResponse()->getContent();
     $this->assertEquals('', $response);
     $this->assertEquals(204, self::$DI['client']->getResponse()->getStatusCode());
     try {
         \databox_field::get_instance(self::$DI['app'], $databox, $fieldId);
         $this->fail('Should have raise an exception');
     } catch (\Exception $e) {
     }
 }
Пример #6
0
 public function createField(Application $app, Request $request, $sbas_id)
 {
     $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
     $data = $this->getFieldJsonFromRequest($app, $request);
     $metaStructure = $databox->get_meta_structure();
     $this->validateNameField($metaStructure, $data);
     $this->validateTagField($data);
     try {
         $field = \databox_field::create($app, $databox, $data['name'], $data['multi']);
         $this->updateFieldWithData($app, $field, $data);
         $field->save();
     } catch (\Exception $e) {
         $app->abort(500, $app->trans('Field %name% could not be created, please try again or contact an admin.', ['%name%' => $data['name']]));
     }
     return $app->json($field->toArray(), 201, ['location' => $app->path('admin_fields_show_field', ['sbas_id' => $sbas_id, 'id' => $field->get_id()])]);
 }