Skip to content

Commit

Permalink
Some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph3nol committed Jun 10, 2012
1 parent 6f12c79 commit 35a6f80
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
24 changes: 13 additions & 11 deletions Manager/Manager.php
Expand Up @@ -148,17 +148,19 @@ public function createNewLink($object)

$this->shortener->setProvider($this->config['entities'][$objectEntityClass]['provider'], $this->config['entities'][$objectEntityClass]['api']);

$link = new Link();
$createdShortUrl = $this->shortener->createShortUrl($this->router->getObjectShowRoute($object));

$link->setObjectEntity(get_class($object));
$link->setObjectId($object->getId());
$link->setShortUrl($createdShortUrl->url);
$link->setHash($createdShortUrl->hash);
$link->setProvider($this->config['entities'][$objectEntityClass]['provider']);

$this->em->persist($link);
$this->em->flush($link);
if ($createdShortUrl = $this->shortener->createShortUrl($this->router->getObjectShowRoute($object))) {
$link = new Link();
$link->setObjectEntity(get_class($object));
$link->setObjectId($object->getId());
$link->setShortUrl($createdShortUrl->url);
$link->setHash($createdShortUrl->hash);
$link->setProvider($this->config['entities'][$objectEntityClass]['provider']);

$this->em->persist($link);
$this->em->flush($link);
} else {
return false;
}

return $link;
}
Expand Down
2 changes: 2 additions & 0 deletions Provider/Bitly.php
Expand Up @@ -78,6 +78,8 @@ public function create()

if ($responseContent->status_code == 200 && $responseContent->status_txt == 'OK') {
$this->creationData = $responseContent->data;
} else {
$this->creationData = null;
}

return $this->creationData;
Expand Down
7 changes: 3 additions & 4 deletions Twig/Extension/UrlShortenerExtension.php
Expand Up @@ -2,7 +2,6 @@

namespace Sly\UrlShortenerBundle\Twig\Extension;

use Symfony\Component\Routing\Route;
use Sly\UrlShortenerBundle\Entity\Link;
use Sly\UrlShortenerBundle\Manager\Manager;
use Sly\UrlShortenerBundle\Manager\ManagerInterface;
Expand Down Expand Up @@ -59,9 +58,9 @@ public function renderShortUrl($item)
if ($link = $this->manager->getLinkEntityFromObject($item)) {
return $link->getShortUrl();
} else {
$newShortLink = $this->manager->createNewLink($item);

return $newShortLink->getShortUrl();
if ($newShortLink = $this->manager->createNewLink($item)) {
return $newShortLink->getShortUrl();
}
}
} else {
/**
Expand Down

0 comments on commit 35a6f80

Please sign in to comment.