Пример #1
0
 public function testGenerateStandardNiceUrl()
 {
     $object = new NiceUrlObject();
     $collection = $this->factory->generate($object);
     $this->assertInstanceOf(get_class(new Collection()), $collection);
     /** @var NiceUrl $niceUrl */
     foreach ($collection as $niceUrl) {
         $this->assertInstanceOf(get_class(new NiceUrl()), $niceUrl, $niceUrl->url);
     }
 }
Пример #2
0
 /**
  * @param NiceUrlInterface $object
  *
  * @throws \yii\db\Exception
  */
 public function runForOne(NiceUrlInterface $object)
 {
     $transaction = \Yii::$app->getDb()->beginTransaction();
     try {
         $factory = new NiceUrlFactory(new DatabaseCounter());
         $niceUrlCollection = $factory->generate($object);
         /** @var NiceUrl $niceUrl */
         foreach ($niceUrlCollection as $niceUrl) {
             NiceUrlRemover::dropOldNiceUrl($niceUrl);
             $niceUrl->save();
         }
         $transaction->commit();
     } catch (\Exception $e) {
         $transaction->rollBack();
         \Yii::getLogger()->log($e->getMessage(), Logger::LEVEL_ERROR, 'niceUrl');
     }
 }