update command
This commit is contained in:
parent
3c66a0b703
commit
b48af47faa
@ -6,6 +6,7 @@ use app\components\Git;
|
||||
use app\models\Package;
|
||||
use Yii;
|
||||
use yii\console\Controller;
|
||||
use yii\helpers\Console;
|
||||
|
||||
class PackageController extends Controller
|
||||
{
|
||||
@ -23,6 +24,8 @@ class PackageController extends Controller
|
||||
|
||||
public function actionImportMtpm()
|
||||
{
|
||||
$file = 'https://raw.githubusercontent.com/rubenwardy/mtpm_lists/gh-pages/lists/mods.csv';
|
||||
$this->stdout('Importing MTPM from ' . $file . "\n");
|
||||
$nameTranslate = [
|
||||
'Crops' => 'crops',
|
||||
];
|
||||
@ -34,7 +37,7 @@ class PackageController extends Controller
|
||||
'/archive-tarball/master.git' => '.git',
|
||||
'https://repo.or.cz/' => 'http://repo.or.cz/',
|
||||
];
|
||||
$csv = array_map('str_getcsv', explode("\n", file_get_contents('https://raw.githubusercontent.com/rubenwardy/mtpm_lists/gh-pages/lists/mods.csv')));
|
||||
$csv = array_map('str_getcsv', explode("\n", file_get_contents($file)));
|
||||
array_shift($csv);
|
||||
foreach ($csv as $row) {
|
||||
if (!isset($row['1'])) {
|
||||
@ -46,7 +49,9 @@ class PackageController extends Controller
|
||||
}
|
||||
$url = trim(trim($row['2'], '/')) . '.git';
|
||||
$url = strtr($url, $urlTranslate);
|
||||
$this->stdout($name . ' ' . $url . ': ');
|
||||
if (!strpos($url, 'github.com') && !strpos($url, 'bitbucket.org') && !strpos($url, 'repo.or.cz')) {
|
||||
$this->stdout('Not on allowed git list, skipping.' . "\n", Console::FG_YELLOW);
|
||||
continue;
|
||||
}
|
||||
$package = Package::find()->where(['name' => $name])->one();
|
||||
@ -62,7 +67,16 @@ class PackageController extends Controller
|
||||
$package->forum = trim($row['4']);
|
||||
if (!$package->authors)
|
||||
$package->authors = [trim($row['0'])];
|
||||
$package->save();
|
||||
if ($package->save()) {
|
||||
$this->stdout('Saved!' . "\n", Console::FG_GREEN);
|
||||
} else {
|
||||
$this->stdout('Errors', Console::FG_RED);
|
||||
foreach ($package->errors as $attribute => $errors) {
|
||||
$this->stdout(' -- ' . $attribute . ' ' . implode(', ', $errors), Console::FG_RED);
|
||||
}
|
||||
$this->stdout("\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
use yii\db\Migration;
|
||||
use yii\db\Schema;
|
||||
|
||||
class m150810_000003_update_package extends Migration
|
||||
class m150811_000001_update_package extends Migration
|
||||
{
|
||||
const TABLE = '{{%package}}';
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user