Exemplo n.º 1
0
 public function req_post()
 {
     if ($this->app->request->get('action') === 'create_bucket') {
         $name = $this->app->request->get('bucket_name');
         $alias = strtolower($name);
         $alias = str_replace(array(' ', '_'), '-', $alias);
         $pattern = Bucket::$regex_id;
         // No name is specified
         if (!$alias) {
             $this->alert('You need to specify a name');
         } elseif (!preg_match($pattern, $alias)) {
             $this->alert('Invalid Alias. Please match <strong>' . $pattern . '</strong>');
         } elseif (Bucket::exists($alias)) {
             $this->alert('Bucket name must be unique across cluster');
         } else {
             $data = array('alias' => array($alias), 'description' => $name, 'roles' => array((string) $this->app->auth->id => 'owner'), 'created' => new \MongoDate(), 'updated' => new \MongoDate());
             $bucket = Bucket::create($data);
             if ($bucket) {
                 $this->alert('Your app was created. <a href="/bucket/' . $alias . '">' . $name . '</a>');
             } else {
                 $this->alert('There was a problem creating your bucket', 'error');
             }
         }
     }
     // Do normal GET request
     return $this->req_get();
 }
Exemplo n.º 2
0
 /**
  * Test that the model abstraction is working
  */
 public function testCreateBucket()
 {
     $bucket_data = array('_id' => 'test-bucket', 'description' => 'Test Bucket');
     $bucket = new Bucket($bucket_data);
     $this->assertFalse(Bucket::exists($bucket->id));
     $bucket->save();
     $this->assertTrue(Bucket::exists($bucket->id));
 }