コード例 #1
0
ファイル: Site.php プロジェクト: boomcms/boom-core
 /**
  * @param SiteModelInterface $site
  *
  * @return $this
  */
 public function makeDefault(SiteModelInterface $site)
 {
     if (!$site->isDefault()) {
         $this->model->where(Model::ATTR_ID, '!=', $site->getId())->update([Model::ATTR_DEFAULT => false]);
         $site->setDefault(true);
         $this->save($site);
     }
     return $this;
 }
コード例 #2
0
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('sites', function (Blueprint $table) {
         $table->increments(Site::ATTR_ID);
         $table->string(Site::ATTR_NAME, 100);
         $table->string(Site::ATTR_HOSTNAME)->unique();
         $table->string(Site::ATTR_ADMIN_EMAIL, 250);
         $table->text(Site::ATTR_ANALYTICS)->nullable();
         $table->boolean(Site::ATTR_DEFAULT)->default(false);
         $table->string(Site::ATTR_SCHEME, 10);
         $table->softDeletes();
     });
     Schema::table('pages', function (Blueprint $table) {
         $table->integer(Page::ATTR_SITE)->unsigned()->references(Site::ATTR_ID)->on('sites')->onUpdate('CASCADE')->onDelete('CASCADE');
     });
     Schema::table('page_urls', function (Blueprint $table) {
         $table->integer(URL::ATTR_SITE)->unsigned()->references(Site::ATTR_ID)->on('sites')->onUpdate('CASCADE')->onDelete('CASCADE');
     });
     Schema::table('groups', function (Blueprint $table) {
         $table->integer(Group::ATTR_SITE)->unsigned()->references(Site::ATTR_ID)->on('sites')->onUpdate('CASCADE')->onDelete('CASCADE');
     });
     Schema::create('asset_site', function (Blueprint $table) {
         $table->integer('asset_id')->unsigned()->references(Asset::ATTR_ID)->on('assets')->onUpdate('CASCADE')->onDelete('CASCADE');
         $table->integer('site_id')->unsigned()->references(Site::ATTR_ID)->on('sites')->onUpdate('CASCADE')->onDelete('CASCADE');
         $table->unique(['asset_id', 'site_id']);
     });
     Schema::create('person_site', function (Blueprint $table) {
         $table->integer('person_id')->unsigned()->references(Person::ATTR_ID)->on('people')->onUpdate('CASCADE')->onDelete('CASCADE');
         $table->integer('site_id')->unsigned()->references(Site::ATTR_ID)->on('sites')->onUpdate('CASCADE')->onDelete('CASCADE');
         $table->unique(['person_id', 'site_id']);
     });
     Schema::table('tags', function (Blueprint $table) {
         $table->integer(Tag::ATTR_SITE)->unsigned()->references(Site::ATTR_ID)->on('sites')->onUpdate('CASCADE')->onDelete('CASCADE');
     });
     $filename = storage_path() . '/boomcms/settings.json';
     if (file_exists($filename)) {
         $settings = (array) json_decode(file_get_contents($filename));
         $site = Site::create([Site::ATTR_DEFAULT => true, Site::ATTR_NAME => $settings['site.name'], Site::ATTR_ADMIN_EMAIL => $settings['site.admin.email'], Site::ATTR_HOSTNAME => '']);
         foreach (['pages', 'page_urls', 'groups', 'tags'] as $table) {
             DB::table($table)->update(['site_id' => $site->getId()]);
         }
         DB::statement("insert into asset_site (asset_id, site_id) select id, '{$site->getId()}' from assets");
         DB::statement("insert into person_site (person_id, site_id) select id, '{$site->getId()}' from people");
     }
     Role::create(['name' => 'manageSites', 'description' => 'Manage sites']);
 }