コード例 #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // Create a couple of websites
     $prod = Website::create(['name' => 'Main Production Website', 'http_host' => 'www.mysite.com', 'environment' => 'production']);
     $test = Website::create(['name' => 'Main Test Website', 'http_host' => 'test.mysite.com', 'environment' => 'test']);
     $dev = Website::create(['name' => 'Development Website', 'http_host' => 'localhost', 'environment' => 'test']);
     // Create some config entries
     ConfigModel::create(['website_id' => $prod->id, 'environment' => 'production', 'group' => 'config', 'key' => 'fruit', 'value' => 'apple-prod-www', 'type' => 'string']);
     ConfigModel::create(['website_id' => $test->id, 'environment' => 'test', 'group' => 'config', 'key' => 'fruit', 'value' => 'banana-test-test', 'type' => 'string']);
     ConfigModel::create(['group' => 'config', 'key' => 'fruit', 'value' => 'orange-default-default', 'type' => 'string']);
     ConfigModel::create(['environment' => 'test', 'group' => 'config', 'key' => 'fruit', 'value' => 'peach-test-default', 'type' => 'string']);
     ConfigModel::create(['environment' => 'production', 'group' => 'config', 'key' => 'fruit', 'value' => 'plum-production-default', 'type' => 'string']);
     ConfigModel::create(['group' => 'config', 'key' => 'animal', 'value' => 'elephant-default-default', 'type' => 'string']);
     ConfigModel::create(['group' => 'config', 'key' => 'bird', 'value' => 'canary-default-default', 'type' => 'string']);
     ConfigModel::create(['group' => 'config', 'key' => 'raptor', 'value' => 'falcon-default-default', 'type' => 'string']);
 }
コード例 #2
0
ファイル: Vobject.php プロジェクト: delatbabel/viewpages
 /**
  * Fetch a object by objectkey or url.
  *
  * Returns a Vobject object for a specific objectkey for the current website.
  *
  * Multiple objects can exist in the vobjects table for any given objectkey.
  *
  * This function finds the correct object in vobjects that matches the
  * given objectkey and belongs to the current website, or if that fails
  * then it will find the correct object in vobjects for the given objectkey
  * that has no relations to any website.
  *
  * @param string $objectkey
  * @return Fluent
  */
 public static function make($objectkey = 'index')
 {
     // Sanitise the key
     $objectkey = filter_var($objectkey, FILTER_SANITIZE_STRING);
     if (empty($objectkey)) {
         // An empty URL indicates that the home object is being fetched.
         $objectkey = 'index';
     }
     // Find the current website ID
     $website_id = Website::currentWebsiteId();
     // Check for a cached copy
     $cache_key = 'vobject__' . $website_id . '__' . $objectkey;
     if (Cache::has($cache_key)) {
         return Cache::get($cache_key);
     }
     // Try to find a object that is joined to the current website
     /** @var Vobject $object */
     $object = static::where('objectkey', '=', $objectkey)->where('website_id', '=', $website_id)->select(['id', 'name', 'content', 'updated_at'])->first();
     if (!empty($object)) {
         #Log::debug(__CLASS__ . ':' . __TRAIT__ . ':' . __FILE__ . ':' . __LINE__ . ':' . __FUNCTION__ . ':' .
         #    'Found vobject on first look,  ID == ' . $object->id);
         $fluent = $object->toFluent();
         Cache::put($cache_key, $fluent, 60);
         return $fluent;
     }
     // If there is no such object, try to find a object that is not joined
     // to any website
     /** @var Vobject $object */
     $object = static::where('objectkey', '=', $objectkey)->whereNull('website_id')->select(['id', 'name', 'content', 'updated_at'])->first();
     if (empty($object)) {
         return null;
     }
     #Log::debug(__CLASS__ . ':' . __TRAIT__ . ':' . __FILE__ . ':' . __LINE__ . ':' . __FUNCTION__ . ':' .
     #    'Found vobject on second look,  ID == ' . $object->id);
     $fluent = $object->toFluent();
     Cache::put($cache_key, $fluent, 60);
     return $fluent;
 }
コード例 #3
0
ファイル: Vpage.php プロジェクト: delatbabel/viewpages
 /**
  * Fetch a page by pagekey or url.
  *
  * Returns a Vpage object for a specific pagekey or URL for the
  * current website.
  *
  * A Vpage object can either be for a specific website or websites,
  * in which case there will be a join table entry in vpage_website
  * containing (vpage_id, website_id), or the Vpage can be for all
  * websites, which means that there will be no join table entry in
  * vpage_website for that vpage_id at all (for any website).
  *
  * Multiple pages can exist in the vpages table for any given URL.
  *
  * This function finds the correct page in vpages that matches the
  * given URL and has a join to the current website, or if that fails
  * then it will find the correct page in vpages for the given URL
  * that has no joins to any website.
  *
  * Finding by URL is common in CMS front ends, otherwise to emulate
  * the functionality of Laravel's View::make() function use the
  * 'pagekey' option.
  *
  * @param string $url
  * @param string $field 'pagekey' or 'url'
  * @return Fluent|null
  */
 public static function fetch($url = 'index', $field = 'pagekey')
 {
     // Sanitise the URL
     $url = filter_var($url, FILTER_SANITIZE_STRING);
     if (empty($url)) {
         // An empty URL indicates that the home page is being fetched.
         $url = 'index';
     }
     #Log::debug(__CLASS__ . ':' . __TRAIT__ . ':' . __FILE__ . ':' . __LINE__ . ':' . __FUNCTION__ . ':' .
     #    'Looking for vpage where ' . $field . ' = ' . $url);
     // Determine whether there is an extension separator on the page
     // key or not, and strip it off if there is one present.
     $url_parts = explode(static::EXTENSION_SEPARATOR, $url, 2);
     $url = $url_parts[0];
     // TODO: The extension for the pagetype is in $url_parts[1] if it
     // is not empty. This could be "blade.php", "php" or "twig".  Restrict
     // the query to pages where the pagetype matches the extension.
     // Find the current website ID
     $website_id = Website::currentWebsiteId();
     // We seem to do a lot of page fetching twice here, often to
     // get the page type, then to get the content and also the updated_at
     // time.  Cache the results after one fetch.
     $cache_key = 'vpage__' . $website_id . '__' . $url;
     if (Cache::has($cache_key)) {
         #Log::debug(__CLASS__ . ':' . __TRAIT__ . ':' . __FILE__ . ':' . __LINE__ . ':' . __FUNCTION__ . ':' .
         #    'Found in cache');
         return Cache::get($cache_key);
     }
     // Try to find a page that is joined to the current website
     /** @var Vpage $page */
     $page = static::where($field, '=', $url)->join('vpage_website', 'vpages.id', '=', 'vpage_website.vpage_id')->where('vpage_website.website_id', '=', $website_id)->select('vpages.id AS id', 'vpages.content AS content', 'vpages.updated_at AS updated_at', 'vpages.pagetype AS pagetype')->first();
     if (!empty($page)) {
         #Log::debug(__CLASS__ . ':' . __TRAIT__ . ':' . __FILE__ . ':' . __LINE__ . ':' . __FUNCTION__ . ':' .
         #    'Found vpage on first look,  ID == ' . $page->id);
         $fluent = $page->toFluent();
         Cache::put($cache_key, $fluent, 60);
         return $fluent;
     }
     // If there is no such page, try to find a page that is not joined
     // to any website
     /** @var Vpage $page */
     $page = static::where($field, '=', $url)->leftJoin('vpage_website', 'vpages.id', '=', 'vpage_website.vpage_id')->whereNull('vpage_website.website_id')->select('vpages.id AS id', 'vpages.content AS content', 'vpages.updated_at AS updated_at', 'vpages.pagetype AS pagetype')->first();
     if (empty($page)) {
         return null;
     }
     #Log::debug(__CLASS__ . ':' . __TRAIT__ . ':' . __FILE__ . ':' . __LINE__ . ':' . __FUNCTION__ . ':' .
     #    'Found vpage on second look,  ID == ' . $page->id);
     $fluent = $page->toFluent();
     Cache::put($cache_key, $fluent, 60);
     return $fluent;
 }
コード例 #4
0
 /**
  * Loads the internal website_id and environment
  *
  * @return ConfigLoaderRepository
  */
 public function loadEnvironment()
 {
     // Fetch the current application environment.
     $this->environment = app()->environment();
     $this->website_id = null;
     // Fetch the current web site data and check to see if it has an
     // alternative environment.
     $website_data = WebsiteModel::currentWebsiteData();
     if (!empty($website_data)) {
         if (!empty($website_data['environment'])) {
             $this->environment = $website_data['environment'];
         }
         // We also want the website ID
         $this->website_id = $website_data['id'];
     }
     $this->cache_key = 'site-config.' . $this->environment . '.' . $this->website_id;
     return $this;
 }