4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-15 05:36:37 +00:00

#313 -- Make the station's short_code a user-editable DB field.

This commit is contained in:
Buster "Silver Eagle" Neece 2017-12-08 03:51:08 -06:00
parent 453e7b442f
commit ec881bfbd4
4 changed files with 85 additions and 51 deletions

View File

@ -46,8 +46,9 @@ return [
'url' => [
'text',
[
'label' => _('Station Web Site URL'),
'label' => _('Station Web Site'),
'class' => 'full-width full-height',
'description' => _('Note: This should be the public-facing homepage of the radio station, not the AzuraCast URL. It will be included in broadcast details.'),
]
],
@ -61,6 +62,14 @@ return [
]
],
'short_name' => [
'text',
[
'label' => _('Advanced: Station URL Stub'),
'description' => _('Optionally specify a short URL-friendly name, such as <code>my_station_name</code>, that will be used in this station\'s URLs. Leave this field blank to automatically create one based on the station name.'),
]
],
'radio_media_dir' => [
'text',
[

View File

@ -0,0 +1,41 @@
<?php declare(strict_types = 1);
namespace Migration;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20171208093239 extends AbstractMigration
{
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE station ADD short_name VARCHAR(100) DEFAULT NULL');
}
public function postUp(Schema $schema)
{
$all_records = $this->connection->fetchAll("SELECT * FROM station");
foreach ($all_records as $record) {
$this->connection->update('station', [
'short_name' => \Entity\Station::getStationShortName($record['name']),
], [
'id' => $record['id'],
]);
}
}
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE station DROP short_name');
}
}

View File

@ -15,22 +15,6 @@ class StationRepository extends BaseRepository
->execute();
}
/**
* @param bool $cached
* @param null $order_by
* @param string $order_dir
* @return array
*/
public function fetchArray($cached = true, $order_by = null, $order_dir = 'ASC')
{
$stations = parent::fetchArray($cached, $order_by, $order_dir);
foreach ($stations as &$station) {
$station['short_name'] = Entity\Station::getStationShortName($station['name']);
}
return $stations;
}
/**
* @param bool $add_blank
* @param \Closure|NULL $display
@ -60,37 +44,13 @@ class StationRepository extends BaseRepository
return $select;
}
/**
* @param bool $cached
* @return array
*/
public function getShortNameLookup($cached = true)
{
$stations = $this->fetchArray($cached);
$lookup = [];
foreach ($stations as $station) {
$lookup[$station['short_name']] = $station;
}
return $lookup;
}
/**
* @param $short_code
* @return null|object
*/
public function findByShortCode($short_code)
{
$short_names = $this->getShortNameLookup();
if (isset($short_names[$short_code])) {
$id = $short_names[$short_code]['id'];
return $this->find($id);
}
return null;
return $this->findOneBy(['short_name' => $short_code]);
}
/**
@ -99,6 +59,8 @@ class StationRepository extends BaseRepository
* @param $data
* @param ContainerInterface $di
* @return Entity\Station
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Exception
*/
public function create($data, ContainerInterface $di)
{
@ -151,6 +113,8 @@ class StationRepository extends BaseRepository
*
* @param Entity\Station $station
* @param ContainerInterface $di
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Exception
*/
public function resetMounts(Entity\Station $station, ContainerInterface $di)
{
@ -180,6 +144,8 @@ class StationRepository extends BaseRepository
/**
* @param Entity\Station $station
* @param ContainerInterface $di
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Exception
*/
public function destroy(Entity\Station $station, ContainerInterface $di)
{

View File

@ -24,10 +24,16 @@ class Station
/**
* @Column(name="name", type="string", length=100, nullable=true)
* @var string|null
* @var string|null The full display name of the station.
*/
protected $name;
/**
* @Column(name="short_name", type="string", length=100, nullable=true)
* @var string|null The URL-friendly name for the station, typically auto-generated from the full station name.
*/
protected $short_name;
/**
* @Column(name="frontend_type", type="string", length=100, nullable=true)
* @var string|null
@ -222,20 +228,32 @@ class Station
return $this->name;
}
/**
* @return string
*/
public function getShortName(): string
{
return self::getStationShortName($this->name);
}
/**
* @param null|string $name
*/
public function setName(string $name = null)
{
$this->name = $name;
if (empty($this->short_name) && !empty($name)) {
$this->short_name = self::getStationShortName($name);
}
}
/**
* @return null|string
*/
public function getShortName(): ?string
{
return $this->short_name ?? self::getStationShortName($this->name);
}
/**
* @param null|string $short_name
*/
public function setShortName(?string $short_name): void
{
$this->short_name = $short_name;
}
/**