Permalink
Browse files

Automatically check for active state

  • Loading branch information...
Thoulah committed Feb 9, 2019
1 parent ecd0c27 commit 23cf2b28cfd88feb396e410b1106aa51329d2642
@@ -6,7 +6,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"component-dir": "../vendor/components",
"component-dir": "../vendor-components",
"vendor-dir": "../vendor"
},
"require": {
@@ -1,7 +1,7 @@
<?php
namespace app\commands;
use Yii;
use app\models\{Console, Video, Webrequest};
use app\models\{Console, Image, Video, Webrequest};
use app\models\lyrics\{Lyrics1Artists, Lyrics2Albums, Lyrics3Tracks};
use yii\console\Controller;
use yii\helpers\ArrayHelper;
@@ -34,9 +34,8 @@ public function actionAlbumImage() {
Console::updateProgress(++$x, $count);
list($width, $height) = getimagesizefromstring($album->image);
$exif = exif_read_data("data://image/jpeg;base64,".base64_encode($album->image));
if ($width === self::ALBUM_IMAGE_DIMENSIONS && $height === self::ALBUM_IMAGE_DIMENSIONS && empty($exif['SectionsFound']) && $exif['MimeType'] === 'image/jpeg' && !is_null($album->image_color)) :
if ($width === self::ALBUM_IMAGE_DIMENSIONS && $height === self::ALBUM_IMAGE_DIMENSIONS && empty($exif['SectionsFound']) && $exif['MimeType'] === 'image/jpeg' && !is_null($album->image_color))
continue;
endif;
Console::write($artist->name, [Console::FG_PURPLE], 3);
Console::write($album->year, [Console::FG_GREEN]);
@@ -52,7 +51,7 @@ public function actionAlbumImage() {
if (($width > self::ALBUM_IMAGE_DIMENSIONS && $height > self::ALBUM_IMAGE_DIMENSIONS) || !empty($exif['SectionsFound']) || $exif['MimeType'] !== 'image/jpeg') :
if ($width >= self::ALBUM_IMAGE_DIMENSIONS && $height >= self::ALBUM_IMAGE_DIMENSIONS) :
$album->image = (Lyrics2Albums::getCover(self::ALBUM_IMAGE_DIMENSIONS, $album))[1];
$album->image = Image::resize($album->image, self::ALBUM_IMAGE_DIMENSIONS);
$album->image_color = self::getAverageImageColor($album->image);
$album->save();
list($width, $height) = getimagesizefromstring($album->image);
@@ -86,9 +85,8 @@ public function actionAlbumPdf() {
foreach ($artists as $artist) :
foreach ($artist->albums as $album) :
Console::updateProgress(++$x, $count);
if (!$album->active || $fileName = Lyrics2Albums::buildPdf($album, $this->renderPartial('@app/views/lyrics/albumPdf', ['tracks' => $album->tracks]))) :
if (!$album->active || $fileName = Lyrics2Albums::buildPdf($album, $this->renderPartial('@app/views/lyrics/albumPdf', ['tracks' => $album->tracks])))
continue;
endif;
Console::write($artist->name, [Console::FG_PURPLE], 3);
Console::write($album->year, [Console::FG_GREEN]);
@@ -17,7 +17,6 @@ public function afterFind(): void {
public function artistsList(): array {
return self::find()
->active()
->orderBy('name')
->all();
}
@@ -30,13 +29,11 @@ public static function albumsList(): BatchQueryResult {
}
public function getAlbums(): LyricsQuery {
return $this->hasMany(Lyrics2Albums::className(), ['parent' => 'id'])
->active();
return $this->hasMany(Lyrics2Albums::className(), ['parent' => 'id']);
}
public static function getLastModified(): int {
$data = self::find()
->active()
->max('updated');
return strtotime($data);
}
@@ -29,7 +29,6 @@ public static function albumsList(string $artist): array {
->innerJoinWith('artist', 'tracks')
->where(['or', Lyrics1Artists::tableName().'.`name`=:artist', Lyrics1Artists::tableName().'.`url`=:artist'])
->addParams([':artist' => $artist])
->active()
->all();
}
@@ -65,14 +64,12 @@ public static function getLastModified(string $artist): int {
->innerJoinWith('artist')
->where(['or', Lyrics1Artists::tableName().'.`name`=:artist', Lyrics1Artists::tableName().'.`url`=:artist'])
->addParams([':artist' => $artist])
->active()
->max(self::tableName().'.updated');
return Yii::$app->formatter->asTimestamp($data);
}
public function getArtist(): LyricsQuery {
return $this->hasOne(Lyrics1Artists::className(), ['id' => 'parent'])
->active();
return $this->hasOne(Lyrics1Artists::className(), ['id' => 'parent']);
}
public function getTracks(): LyricsQuery {
@@ -49,13 +49,11 @@ public static function getLastModified(string $artist, string $year, string $nam
public function getArtist(): ActiveQuery {
return $this->hasOne(Lyrics1Artists::class, ['id' => 'parent'])
->active()
->via('album');
}
public function getAlbum(): ActiveQuery {
return $this->hasOne(Lyrics2Albums::className(), ['id' => 'parent'])
->active();
return $this->hasOne(Lyrics2Albums::className(), ['id' => 'parent']);
}
public function getLyrics(): ActiveQuery {
@@ -1,11 +1,13 @@
<?php
namespace app\models\lyrics;
use Yii;
use yii\helpers\ArrayHelper;
class LyricsQuery extends \yii\db\ActiveQuery {
public function active(): self {
if (php_sapi_name() === 'cli' || (!Yii::$app->user->isGuest && Yii::$app->user->identity->isAdmin))
return $this->onCondition([]);
public function init(): ?self {
parent::init();
if (php_sapi_name() === 'cli' || (!Yii::$app->user->isGuest && Yii::$app->user->identity->isAdmin) || ArrayHelper::isIn($this->modelClass::tableName(), [Lyrics3Tracks::tableName(), Lyrics4Lyrics::tableName()]))
return null;
return $this->onCondition([$this->modelClass::tableName().'.active' => true]);
}

0 comments on commit 23cf2b2

Please sign in to comment.