From 805b7f4bc118ba9788afe46bf9f51444f55cd067 Mon Sep 17 00:00:00 2001 From: cornernote Date: Mon, 10 Aug 2015 21:46:54 +0930 Subject: [PATCH] store serialized data in binary fields --- .gitignore | 3 +- composer.json | 3 +- composer.lock | 48 ++++++- src/commands/PackageController.php | 124 +----------------- src/components/Serialize.php | 71 ++++++++++ src/config/init.php | 3 + .../m150810_000003_update_package.php | 37 ++++++ src/models/Package.php | 9 +- web/index.php | 1 - yii | 1 - 10 files changed, 173 insertions(+), 127 deletions(-) create mode 100644 src/components/Serialize.php create mode 100644 src/migrations/m150810_000003_update_package.php diff --git a/.gitignore b/.gitignore index 1eb2931..0793bc7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ .idea +.env .DS_Store Thumbs.db -composer.phar vendor/ -_bak/ TestController.php diff --git a/composer.json b/composer.json index 4e0f02b..dfd7e7b 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "kartik-v/yii2-widgets": "^3.4", "cebe/markdown": "~1.0.1", "bigpaulie/yii2-fancybox": "^1.0", - "knplabs/github-api": "^1.4" + "knplabs/github-api": "^1.4", + "vlucas/phpdotenv": "^2.0" }, "require-dev": { "yiisoft/yii2-debug": "*", diff --git a/composer.lock b/composer.lock index 12d6298..764c9bc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "965938d21f9aeba1f8b806a2097de818", + "hash": "e417d5aeb8ba7262be04e24edd001b90", "packages": [ { "name": "bigpaulie/yii2-fancybox", @@ -1768,6 +1768,52 @@ "homepage": "https://symfony.com", "time": "2015-06-18 19:21:56" }, + { + "name": "vlucas/phpdotenv", + "version": "v2.0.1", + "source": { + "type": "git", + "url": "https://github.com/vlucas/phpdotenv.git", + "reference": "91064290f5b53a09bdff1b939d7f69fb0e7531b5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/91064290f5b53a09bdff1b939d7f69fb0e7531b5", + "reference": "91064290f5b53a09bdff1b939d7f69fb0e7531b5", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Dotenv\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD" + ], + "authors": [ + { + "name": "Vance Lucas", + "email": "vance@vancelucas.com", + "homepage": "http://www.vancelucas.com" + } + ], + "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", + "homepage": "http://github.com/vlucas/phpdotenv", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "time": "2015-05-30 16:15:01" + }, { "name": "yiisoft/yii2", "version": "2.0.6", diff --git a/src/commands/PackageController.php b/src/commands/PackageController.php index cf4224f..435a971 100644 --- a/src/commands/PackageController.php +++ b/src/commands/PackageController.php @@ -23,110 +23,6 @@ class PackageController extends Controller public function actionImportMtpm() { - $ignore = [ - 'lulzpack', - 'lift', - 'Animalsmod', - 'admin_tools', - 'extrachests', - 'bettercoal', - 'slabrealm', - 'mccarpet', - 'clock', - 'helicopter', - 'mudslide', - 'beacon', - 'books_plus', - 'nyancats_plus', - 'realclocks', - 'Marble_Blocks', - 'chests_0gb_us', - 'kerova', - 'chatlog', - 'airship', - 'treasurer', - 'alphabet', - 'DOM-modpack-all', - 'whereis', - 'fireworks', - 'components', - 'senderman', - 'glowcrystals', - 'magic_latern', - 'mod3', - 'greenscreens', - 'creative', - 'digicode', - 'armor', - 'xray', - 'octublock', - 'mudslide', - 'secret', - 'no_guests', - 'papyrus_door', - 'terror', - 'mblocks', - 'uranium', - 'fishing', - 'bigchests', - 'signs', - 'future_ban', - 'candles', - 'birthstones', - 'camomod', - 'chains', - 'docfarming', - 'drippingwater', - 'oneclick', - 'my_mobs', - 'mint', - 'cgmr', - 'watch', - 'workbench', - 'noncubic', - 'nuke', - 'weblock', - 'sea', - 'bedrock', - 'bones', - 'gauges', - 'hovers', - 'itemframes', - 'item_drop', - 'names_per_ip', - 'paintings', - 'snow', - 'flint', - 'camouflage', - 'glowstone', - 'diamond_fist', - 'mines', - 'mailbox', - 'jukebox', - 'altertrunks', - 'thaumtest', - 'blox', - 'bone', - 'crafting', - 'dplus', - 'fences', - 'compass', - 'sethome', - 'xfences', - 'camo_modpack', - 'painting', - 'tbm', - 'brillantblocks', - 'flags', - 'gems', - 'infinitytools', - 'lavacooling', - 'chat_channel', - - // gitorious - 'building_blocks', - 'desert_uses', - ]; $nameTranslate = [ 'Crops' => 'crops', ]; @@ -148,9 +44,6 @@ class PackageController extends Controller if (in_array($name, array_keys($nameTranslate))) { $name = $nameTranslate[$name]; } - if (in_array($name, $ignore)) { - continue; - } $url = trim(trim($row['2'], '/')) . '.git'; $url = strtr($url, $urlTranslate); $package = Package::find()->where(['name' => $name])->one(); @@ -160,16 +53,13 @@ class PackageController extends Controller } else { $package->checkUrl = false; } - $package->url = $url; - $package->homepage = trim($row['4']); - $package->authors = [trim($row['0'])]; - - //$package->checkUrl = false; - if (!$package->save()) { - print_r($package->errors); - print_r($package->attributes); - die; - } + if (!$package->url) + $package->url = $url; + if (!$package->homepage) + $package->homepage = trim($row['4']); + if (!$package->authors) + $package->authors = [trim($row['0'])]; + $package->save(); } } diff --git a/src/components/Serialize.php b/src/components/Serialize.php new file mode 100644 index 0000000..17d5834 --- /dev/null +++ b/src/components/Serialize.php @@ -0,0 +1,71 @@ +load(); + defined('YII_DEBUG') or define('YII_DEBUG', getenv('YII_DEBUG') ? (getenv('YII_DEBUG') == 'false' ? false : getenv('YII_DEBUG')) : true); defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV') ? getenv('YII_ENV') : 'dev'); \ No newline at end of file diff --git a/src/migrations/m150810_000003_update_package.php b/src/migrations/m150810_000003_update_package.php new file mode 100644 index 0000000..0ee2681 --- /dev/null +++ b/src/migrations/m150810_000003_update_package.php @@ -0,0 +1,37 @@ +dropColumn(self::TABLE, 'bower'); + $this->dropColumn(self::TABLE, 'readme'); + $this->dropColumn(self::TABLE, 'screenshots'); + $this->dropColumn(self::TABLE, 'authors'); + $this->dropColumn(self::TABLE, 'license'); + $this->addColumn(self::TABLE, 'bower', Schema::TYPE_BINARY); + $this->addColumn(self::TABLE, 'readme', Schema::TYPE_BINARY); + $this->addColumn(self::TABLE, 'screenshots', Schema::TYPE_BINARY); + $this->addColumn(self::TABLE, 'authors', Schema::TYPE_BINARY); + $this->addColumn(self::TABLE, 'license', Schema::TYPE_BINARY); + } + + public function down() + { + $this->dropColumn(self::TABLE, 'bower'); + $this->dropColumn(self::TABLE, 'readme'); + $this->dropColumn(self::TABLE, 'screenshots'); + $this->dropColumn(self::TABLE, 'authors'); + $this->dropColumn(self::TABLE, 'license'); + $this->addColumn(self::TABLE, 'bower', Schema::TYPE_TEXT); + $this->addColumn(self::TABLE, 'readme', Schema::TYPE_TEXT); + $this->addColumn(self::TABLE, 'screenshots', Schema::TYPE_TEXT); + $this->addColumn(self::TABLE, 'authors', Schema::TYPE_TEXT); + $this->addColumn(self::TABLE, 'license', Schema::TYPE_TEXT); + } +} \ No newline at end of file diff --git a/src/models/Package.php b/src/models/Package.php index 555bee7..4fd129c 100644 --- a/src/models/Package.php +++ b/src/models/Package.php @@ -3,6 +3,7 @@ namespace app\models; use app\components\Git; +use app\components\Serialize; use app\models\query\PackageQuery; use bigpaulie\fancybox\FancyBox; use cebe\markdown\GithubMarkdown; @@ -70,8 +71,8 @@ class Package extends ActiveRecord [['name', 'url'], 'trim'], [['name'], 'match', 'pattern' => '/^[-a-z0-9_]+$/', 'message' => '{attribute} can only contain lowercase letters, numbers, "_" and "-"'], [['url'], 'match', 'pattern' => '%(git|http(s)?)(:(//)?)([\w./\-~]+)(\.git)%', 'message' => '{attribute} must be a valid git endpoint.'], - [['url'], function ($attribute, $params) { - if ($this->checkUrl && Git::getFile($this->$attribute, '') === false) { + [['url'], function ($attribute) { + if ($this->checkUrl && Git::getFile($this->$attribute) === false) { $this->addError($attribute, 'Could not fetch remote repository.'); } }], @@ -172,7 +173,7 @@ class Package extends ActiveRecord if (!$this->serialized) { foreach ($this->serializeAttributes as $attribute) { if ($this->$attribute) { - $this->$attribute = json_encode($this->$attribute); + $this->$attribute = [Serialize::serialize($this->$attribute), \PDO::PARAM_LOB]; } } $this->serialized = true; @@ -187,7 +188,7 @@ class Package extends ActiveRecord if ($this->serialized) { foreach ($this->serializeAttributes as $attribute) { if ($this->$attribute) { - $this->$attribute = json_decode($this->$attribute, true); + $this->$attribute = Serialize::unserialize($this->$attribute); } } $this->serialized = false; diff --git a/web/index.php b/web/index.php index d50430a..00a39a3 100644 --- a/web/index.php +++ b/web/index.php @@ -1,7 +1,6 @@