Inheritance: use trait Webiny\Component\StdLib\ComponentTrait, use trait Webiny\Component\StdLib\StdLibTrait
Example #1
0
 /**
  * Base constructor.
  *
  * @param string $config Path to the MaxMind configuration.
  *
  * @throws \Webiny\Component\StdLib\Exception\Exception
  */
 public function __construct($config)
 {
     $config = \Webiny\Component\Config\Config::getInstance()->yaml($config);
     // bootstrap
     Mongo::setConfig(['Mongo' => $config->get('Mongo', null, true)]);
     Entity::setConfig(['Entity' => $config->get('Entity', null, true)]);
 }
Example #2
0
 /**
  * Import IPv6 entries.
  */
 public function importIp6CityBlock()
 {
     // city blocks db file
     $cbFile = $this->dbFolder . 'GeoLite2-City-Blocks-IPv6.csv';
     // start the import
     echo "\nImporting city IPv6 block ... please give it couple of minutes to finish. (about 5min)";
     $handle = fopen($cbFile, "r");
     fgetcsv($handle, 0, ",");
     // remove the header row
     while (($row = fgetcsv($handle, 0, ",")) !== false) {
         // calculate ip range block
         $cidrRange = Ipv6Helper::calculateIpv6CidrRange($row[0]);
         // save the record
         $cityBlockEntity = new CityBlockIp6Entity();
         $cityBlockEntity->rangeStart = $cidrRange['start'];
         $cityBlockEntity->rangeEnd = $cidrRange['end'];
         $cityBlockEntity->geoId = (int) $row[1];
         $cityBlockEntity->save();
     }
     fclose($handle);
     // ensure range index
     $index = new SingleIndex('ipStart', 'rangeStart');
     $this->mongo->createIndex('GeoIpCityBlockIp6', $index);
     echo "\nCity IPv6 block import done\n";
 }
Example #3
0
File: Mongo.php Project: webiny/hrc
 /**
  * Installs the required mongo collection for cache storage and creates the required indexes.
  *
  * @return bool
  */
 public function installCollections()
 {
     $collections = $this->mongoInstance->listCollections();
     foreach ($collections as $collection) {
         /* @var $collection CollectionInfo */
         if ($collection->getName() == self::collection) {
             return true;
         }
     }
     $this->mongoInstance->createCollection(self::collection);
     $this->mongoInstance->createIndex(self::collection, new SingleIndex('key', 'key', false, true));
     $this->mongoInstance->createIndex(self::collection, new SingleIndex('ttl', 'ttl', false, false, false, 0));
     return true;
 }
Example #4
0
 public static function setUpBeforeClass()
 {
     Mongo::setConfig(realpath(__DIR__ . '/' . self::MONGO_CONFIG));
     Entity::setConfig(realpath(__DIR__ . '/' . self::CONFIG));
     /**
      * Make sure no collections exist
      */
     self::mongo()->dropCollection('Author');
     self::mongo()->dropCollection('Page');
     self::mongo()->dropCollection('Comment');
     self::mongo()->dropCollection('Label');
     self::mongo()->dropCollection('Label2Page');
     /**
      * Create some test entity instances
      */
     $page = new Page();
     $author = new Author();
     $comment = new Comment();
     $label = new Label();
     $label2 = new Label();
     /**
      * Try simple assignment (should trigger assign via magic method)
      */
     $author->name = 'Pavel Denisjuk';
     /**
      * Assign using regular way
      */
     $comment->getAttribute('text')->setValue('Best blog post ever!');
     $label->getAttribute('label')->setValue('marketing');
     $label2->getAttribute('label')->setValue('seo');
     $page->getAttribute('title')->setValue('First blog post');
     $page->getAttribute('publishOn')->setValue('2014-11-01');
     $page->getAttribute('remindOn')->setValue(time());
     $page->getAttribute('author')->setValue($author);
     $page->getAttribute('settings')->setValue(['key1' => 'value1', 'key2' => ['key3' => 'value3']]);
     $page->getAttribute('comments')->add($comment);
     $page->getAttribute('labels')->add([$label, $label2]);
     self::$page = $page;
 }
Example #5
0
 /**
  * Creates the necessary indexes and collections if they don't exist.
  */
 private function createCollections()
 {
     $collections = $this->mongo->listCollections();
     $collectionsCreated = false;
     foreach ($collections as $collection) {
         /* @var $collection CollectionInfo */
         if ($collection->getName() == self::ADB_STATS_DAILY) {
             $collectionsCreated = true;
             break;
         }
     }
     if (!$collectionsCreated) {
         // create collections
         $this->mongo->createCollection(self::ADB_STATS_DAILY);
         $this->mongo->createCollection(self::ADB_STATS_MONTHLY);
         $this->mongo->createCollection(self::ADB_DIMS);
         // ensure indexes
         $this->mongo->createIndex(self::ADB_STATS_DAILY, new CompoundIndex('entityTsEntry', ['entity', 'ref', 'ts'], true, true));
         $this->mongo->createIndex(self::ADB_STATS_MONTHLY, new CompoundIndex('entityMonthEntry', ['entity', 'ref', 'ts'], true, true));
         $this->mongo->createIndex(self::ADB_DIMS, new CompoundIndex('dimension', ['name', 'value', 'entity', 'ts'], true, true));
         $this->mongo->createIndex(self::ADB_DIMS, new CompoundIndex('dimension_entity', ['entity', 'ts'], true));
     }
 }
Example #6
0
 public function driverSet()
 {
     Mongo::setConfig(realpath(__DIR__ . '/' . self::CONFIG));
     return [[$this->mongo()]];
 }
Example #7
0
 public function setUp()
 {
     \Webiny\Component\Mongo\Mongo::setConfig(new ConfigObject(['Driver' => 'Webiny\\AnalyticsDb\\Test\\MongoDriverMock']));
     $this->instance = new Query\Dimensions(new Mongo('localhost', 'testDb'), 'browser', 100, DateHelper::today());
 }
Example #8
0
 public function setUp()
 {
     \Webiny\Component\Mongo\Mongo::setConfig(new ConfigObject(['Driver' => 'Webiny\\AnalyticsDb\\Test\\MongoDriverMock']));
     $this->instance = new AnalyticsDb(new Mongo('localhost', 'testDb'));
 }
Example #9
0
<?php

require_once '../vendor/autoload.php';
\Webiny\Component\Security\Security::setConfig('./securityConfig.yaml');
\Webiny\Component\Mongo\Mongo::setConfig('./mongoConfig.yaml');
\Webiny\Component\Entity\Entity::setConfig('./entityConfig.yaml');
$security = \Webiny\Component\Security\Security::getInstance();
$loginConfig = \Webiny\Component\Config\Config::getInstance()->yaml('./loginConfig.yaml');
$login = new \Webiny\Login\Login($security, $loginConfig);
Example #10
0
 /**
  * This method does your query lookup and returns the result in form of an array.
  * In case if there are no records to return, false is returned.
  *
  * @return bool
  */
 public function getResult()
 {
     $result = $this->mongo->aggregate($this->getCollectionName(), $this->getPipeline());
     return $result->toArray();
 }
Example #11
0
 public static function setUpBeforeClass()
 {
     Mongo::setConfig(realpath(__DIR__ . '/' . self::MONGO_CONFIG));
     Entity::setConfig(realpath(__DIR__ . '/' . self::CONFIG));
     self::deleteAllTestCollections();
 }
Example #12
0
 public function setUp()
 {
     Mongo::setConfig(realpath(__DIR__ . '/' . self::CONFIG));
 }