public function run()
 {
     DB::table('sites')->delete();
     for ($i = 0; $i < 5; $i++) {
         for ($j = 0; $j < 5; $j++) {
             Site::create(array('name' => 'BTS_' . $i . $j));
         }
     }
 }
 /**
  * test HABM operations without clobbering existing records #275
  *
  * @return void
  */
 public function testHABTMKeepExisting()
 {
     $this->loadFixtures('Site', 'Domain', 'DomainsSite');
     $Site = new Site();
     $results = $Site->find('count');
     $expected = 3;
     $this->assertEquals($expected, $results);
     $data = $Site->findById(1);
     // include api.cakephp.org
     $data['Domain'] = array('Domain' => array(1, 2, 3));
     $Site->save($data);
     $Site->id = 1;
     $results = $Site->read();
     $expected = 3;
     // 3 domains belonging to cakephp
     $this->assertEquals($expected, count($results['Domain']));
     $Site->id = 2;
     $results = $Site->read();
     $expected = 2;
     // 2 domains belonging to markstory
     $this->assertEquals($expected, count($results['Domain']));
     $Site->id = 3;
     $results = $Site->read();
     $expected = 2;
     $this->assertEquals($expected, count($results['Domain']));
     $results['Domain'] = array('Domain' => array(7));
     $Site->save($results);
     // remove association from domain 6
     $results = $Site->read();
     $expected = 1;
     // only 1 domain left belonging to rchavik
     $this->assertEquals($expected, count($results['Domain']));
     // add deleted domain back
     $results['Domain'] = array('Domain' => array(6, 7));
     $Site->save($results);
     $results = $Site->read();
     $expected = 2;
     // 2 domains belonging to rchavik
     $this->assertEquals($expected, count($results['Domain']));
     $Site->DomainsSite->id = $results['Domain'][0]['DomainsSite']['id'];
     $Site->DomainsSite->saveField('active', true);
     $results = $Site->Domain->DomainsSite->find('count', array('conditions' => array('DomainsSite.active' => true)));
     $expected = 5;
     $this->assertEquals($expected, $results);
     // activate api.cakephp.org
     $activated = $Site->DomainsSite->findByDomainId(3);
     $activated['DomainsSite']['active'] = true;
     $Site->DomainsSite->save($activated);
     $results = $Site->DomainsSite->find('count', array('conditions' => array('DomainsSite.active' => true)));
     $expected = 6;
     $this->assertEquals($expected, $results);
     // remove 2 previously active domains, and leave $activated alone
     $data = array('Site' => array('id' => 1, 'name' => 'cakephp (modified)'), 'Domain' => array('Domain' => array(3)));
     $Site->create($data);
     $Site->save($data);
     // tests that record is still identical prior to removal
     $Site->id = 1;
     $results = $Site->read();
     unset($results['Domain'][0]['DomainsSite']['updated']);
     unset($activated['DomainsSite']['updated']);
     $this->assertEquals($activated['DomainsSite'], $results['Domain'][0]['DomainsSite']);
 }
 public function createSiteAction()
 {
     $domains = $this->_getParam("domains");
     $domains = str_replace(" ", "", $domains);
     $domains = explode(",", $domains);
     $site = Site::create(array("rootId" => intval($this->_getParam("id")), "domains" => $domains));
     $site->save();
     $this->_helper->json($site);
 }
Beispiel #4
0
 private function site_create()
 {
     if (!isset($_POST['url']) || empty($_POST['url'])) {
         // @todo redirect to site create page
         trigger_error('Please enter a URL.', E_USER_ERROR);
         exit;
     }
     $site = Site::create(array('url' => $_POST['url']));
     // redirect to site display page
     header("HTTP/1.1 301 Moved Permanently");
     header("Location: " . Options::get('base_url') . "site/?id=" . $site->id);
     exit;
 }
 public function store()
 {
     $site = Site::create(Input::all());
     Session::put('siteId', $site->id);
     return $site;
 }