Exemplo n.º 1
0
 public function testDelete()
 {
     Config::set('chimpanzee', 'CTO');
     Config::set('platypus', 'CEO');
     $this->assertEquals('CTO', Config::get('chimpanzee'));
     $this->assertEquals('CEO', Config::get('platypus'));
     Config::delete('platypus');
     $this->assertNull(Config::get('platypus'));
     $this->assertNotNull(Config::get('chimpanzee'));
 }
Exemplo n.º 2
0
 function getConfig()
 {
     $config = array();
     // get the raw db output
     $table_rows = $this->get_tables();
     // exit if no config is returned
     if (!is_array($table_rows)) {
         return false;
     }
     // clean up data in a better format
     foreach ($table_rows as $table => $rows) {
         // create the config table if it doesn't exist
         if (!array_key_exists($table, $config)) {
             $config[$table] = array();
         }
         foreach ($rows as $row) {
             // delete a duplicate key
             if (array_key_exists($row['key'], $config[$table])) {
                 // backwards compatibility - see if there's an id available
                 if ($row['id']) {
                     $c = new Config($row['id'], $table);
                     // delete entry
                     $c->delete();
                 }
             } else {
                 $config[$table][$row['key']] = $row['value'];
             }
         }
     }
     // verify config against the setup
     foreach ($config as $type => $properties) {
         $is_plugin = getPath($type . "/bin/config.php");
         $is_controller = getPath("controllers/" . $type . ".php");
         // delete the config entry if no controller/plugin found
         if (!$is_plugin && !$is_controller) {
             unset($config[$type]);
             $this->unregister($type);
         }
     }
     return $config;
 }
Exemplo n.º 3
0
 public function action_index()
 {
     Config::load('password', true);
     $reset = Config::get('password.reset');
     $data['instaled'] = true;
     $data['errors'] = '';
     if ($reset) {
         $data['pass1'] = '';
         $data['pass2'] = '';
         if ($_POST) {
             $data = $_POST;
             $data['errors'] = array();
             $data['instaled'] = true;
             $val = Validation::forge('users');
             $val->add_field('pass1', 'New Password', 'required|min_length[4]|max_length[40]');
             $val->add_field('pass2', 'Repeat', 'required|min_length[4]|max_length[40]');
             if ($val->run()) {
                 if ($val->validated('pass1') != $val->validated('pass2')) {
                     $data['errors'] = array('New password and confirmation password do not match!');
                 } else {
                     Config::load('install', true);
                     $name = Config::get('install.user');
                     $user = \Sentry::user($name);
                     $update = $user->update(array('password' => $val->validated('pass2')));
                     Config::delete('password.reset');
                     Config::save('password', 'password');
                     return Response::forge(View::forge('install/newpass', $data));
                 }
             } else {
                 $data['errors'] = $val->error();
             }
         }
         return Response::forge(View::forge('install/reset', $data));
     } else {
         return Response::forge(View::forge('noclayer/404'), 404);
     }
 }
Exemplo n.º 4
0
 /**
  * Alias to Config::delete()
  * Removes a given config item (key)
  *
  * @param string $key   The key of the config item we're removing
  *
  * @return  Config_Group
  */
 public function offsetUnset($key)
 {
     if ($this->offsetExists($key)) {
         Config::delete($this->_group, $key);
         unset($this->_contents[$key]);
     }
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Delete a design setting
  *
  * // XXX: Maybe this should go in Design? --Z
  *
  * @return mixed $result false if something didn't work
  */
 function deleteSetting($section, $setting)
 {
     $config = new Config();
     $config->section = $section;
     $config->setting = $setting;
     if ($config->find(true)) {
         $result = $config->delete();
         if (!$result) {
             common_log_db_error($config, 'DELETE', __FILE__);
             // TRANS: Client error message
             $this->clientError(_("Unable to delete design setting."));
             return null;
         }
     }
     return $result;
 }
Exemplo n.º 6
0
 /**
  * @test
  */
 public function testComplexSubKeys()
 {
     $c = new Config();
     // 1
     $c->set('t3.test1.foo.bar.asd', false);
     $this->assertTrue($c->exists('t3.test1.foo.bar.asd'));
     $this->assertTrue($c->exists('t3.test1.foo.bar'));
     $this->assertTrue($c->exists('t3.test1.foo'));
     $this->assertTrue($c->exists('t3.test1'));
     // 2
     $t2a->a = 'b';
     $t2b->foo = 'bar';
     $t2b->bar = array('a' => $t2a, 'b' => false);
     $t2c = array('foo' => $t2b, 'bar' => 666);
     $c->set('t3.test2', $t2c);
     // 2 - getting
     $this->assertEquals($t2c, $c->get('t3.test2'));
     $this->assertEquals($t2b, $c->get('t3.test2.foo'));
     $this->assertSame(666, $c->get('t3.test2.bar'));
     $this->assertSame('bar', $c->get('t3.test2.foo.foo'));
     $this->assertEquals($t2b->bar, $c->get('t3.test2.foo.bar'));
     $this->assertFalse($c->get('t3.test2.foo.bar.b'));
     $this->assertSame($t2a, $c->get('t3.test2.foo.bar.a'));
     $this->assertSame('b', $c->get('t3.test2.foo.bar.a.a'));
     // 2 - exists
     $this->assertTrue($c->exists('t3.test2'));
     $this->assertTrue($c->exists('t3.test2.foo'));
     $this->assertTrue($c->exists('t3.test2.bar'));
     $this->assertTrue($c->exists('t3.test2.foo.foo'));
     $this->assertTrue($c->exists('t3.test2.foo.bar'));
     $this->assertTrue($c->exists('t3.test2.foo.bar.b'));
     $this->assertTrue($c->exists('t3.test2.foo.bar.a'));
     // 2 - setting
     $c->set('t3.test2.foo.bar.a.a', true);
     $this->assertTrue($c->get('t3.test2.foo.bar.a.a'));
     // 2 - deleting
     $c->delete('t3.test2.foo.bar.a');
     $this->assertFalse($c->exists('t3.test2.foo.bar.a'));
     $this->assertFalse($c->exists('t3.test2.foo.bar.a.a'));
     $c->delete('t3.test2.foo.bar');
     $this->assertFalse($c->exists('t3.test2.foo.bar'));
     $this->assertFalse($c->exists('t3.test2.foo.bar.b'));
     $this->assertFalse($c->exists('t3.test2.foo.bar.a'));
     $c->delete('t3.test2.nosuchkey');
 }
Exemplo n.º 7
0
 /**
  * Test
  *
  * @return void
  */
 public function testSetValue()
 {
     $this->object->insert(array('identifier' => 'string_identifier', 'value' => 'string_result_insert_value'));
     $this->assertTrue((bool) $this->object->setValue('string_identifier', 'string_result_insert_new_value'));
     $this->object->delete(array('identifier' => 'string_identifier'));
 }