diff --git a/src/Distilleries/Contentful/Commands/Sync/Traits/SyncTrait.php b/src/Distilleries/Contentful/Commands/Sync/Traits/SyncTrait.php index e65cc3a..527fb5e 100755 --- a/src/Distilleries/Contentful/Commands/Sync/Traits/SyncTrait.php +++ b/src/Distilleries/Contentful/Commands/Sync/Traits/SyncTrait.php @@ -53,7 +53,8 @@ protected function dumpSql(string $path, string $connector) { $exec = 'export MYSQL_PWD=\'%s\'; mysqldump --add-drop-table --default-character-set=%s %s -u %s -h %s --port %s > %s'; - $command = sprintf($exec, + $command = sprintf( + $exec, addcslashes(config('database.connections.' . $connector . '.password'), "'"), config('database.connections.' . $connector . '.charset'), config('database.connections.' . $connector . '.database'), @@ -107,7 +108,8 @@ protected function putSql(string $path, string $connector) { $exec = 'export MYSQL_PWD=\'%s\'; mysql -u %s -h %s --port %s %s < %s'; - $command = sprintf($exec, + $command = sprintf( + $exec, addcslashes(config('database.connections.' . $connector . '.password'), "'"), config('database.connections.' . $connector . '.username'), config('database.connections.' . $connector . '.host'), diff --git a/src/Distilleries/Contentful/Models/Base/ContentfulMapper.php b/src/Distilleries/Contentful/Models/Base/ContentfulMapper.php index 0f8fd32..4262110 100755 --- a/src/Distilleries/Contentful/Models/Base/ContentfulMapper.php +++ b/src/Distilleries/Contentful/Models/Base/ContentfulMapper.php @@ -137,7 +137,7 @@ protected function mapRelationships($payload): array if (is_array($value)) { if ($this->isLink($value)) { try { - $relationships[] = $this->relationshipSignature($value,$field); + $relationships[] = $this->relationshipSignature($value, $field); } catch (Exception $e) { // } @@ -145,7 +145,7 @@ protected function mapRelationships($payload): array foreach ($value as $entry) { if ($this->isLink($entry)) { try { - $relationships[] = $this->relationshipSignature($entry,$field); + $relationships[] = $this->relationshipSignature($entry, $field); } catch (Exception $e) { // } diff --git a/src/Distilleries/Contentful/Models/Locale.php b/src/Distilleries/Contentful/Models/Locale.php index 36a71f0..6e8f264 100755 --- a/src/Distilleries/Contentful/Models/Locale.php +++ b/src/Distilleries/Contentful/Models/Locale.php @@ -177,7 +177,7 @@ public static function getLocale(string $code): string $tab = explode('_', $code); return Str::lower($tab[0]); - } else if (Str::contains($code, '-')) { + } elseif (Str::contains($code, '-')) { $tab = explode('-', $code); return Str::lower($tab[0]); @@ -198,7 +198,7 @@ public static function getCountry(string $code): string $tab = explode('_', $code); return Str::lower($tab[1]); - } else if (Str::contains($code, '-')) { + } elseif (Str::contains($code, '-')) { $tab = explode('-', $code); return Str::lower($tab[1]); diff --git a/src/Distilleries/Contentful/Models/Scopes/ValidatedScope.php b/src/Distilleries/Contentful/Models/Scopes/ValidatedScope.php index 5520d26..494a787 100644 --- a/src/Distilleries/Contentful/Models/Scopes/ValidatedScope.php +++ b/src/Distilleries/Contentful/Models/Scopes/ValidatedScope.php @@ -22,7 +22,7 @@ public function apply(Builder $builder, Model $model) ->where(function ($query) use ($model) { $query ->whereNull($model->getTable() . '.validated_at') - ->orWhere($model->getTable() . '.validated_at','>=',Carbon::now()->format('Y-m-d H:i:s')); + ->orWhere($model->getTable() . '.validated_at', '>=', Carbon::now()->format('Y-m-d H:i:s')); }); $this->extend($builder); diff --git a/src/Distilleries/Contentful/Repositories/AssetsRepository.php b/src/Distilleries/Contentful/Repositories/AssetsRepository.php index d004a6f..09860d9 100755 --- a/src/Distilleries/Contentful/Repositories/AssetsRepository.php +++ b/src/Distilleries/Contentful/Repositories/AssetsRepository.php @@ -167,7 +167,8 @@ protected function getFieldValue(array $fields, string $field, string $locale, s { return ! empty($fields[$field][$locale]) ? $fields[$field][$locale] : - (! empty($fields[$field][$fallbackLocale]) ? $fields[$field][$fallbackLocale] : + ( + ! empty($fields[$field][$fallbackLocale]) ? $fields[$field][$fallbackLocale] : (! empty($secondFallback) && ! empty($fields[$field][$secondFallback]) ? $fields[$field][$secondFallback] : $default) ); } diff --git a/src/Distilleries/Contentful/Repositories/EntriesRepository.php b/src/Distilleries/Contentful/Repositories/EntriesRepository.php index bcd88e5..be0cd61 100755 --- a/src/Distilleries/Contentful/Repositories/EntriesRepository.php +++ b/src/Distilleries/Contentful/Repositories/EntriesRepository.php @@ -60,7 +60,7 @@ public function toContentfulModel(array $entry, Collection $locales) if (! empty($model)) { if (isset($localeEntry['relationships'])) { - $this->handleRelationships($localeEntry['locale'],$localeEntry['country'], $localeEntry['contentful_id'], $this->entryContentType($entry), $localeEntry['relationships']); + $this->handleRelationships($localeEntry['locale'], $localeEntry['country'], $localeEntry['contentful_id'], $this->entryContentType($entry), $localeEntry['relationships']); unset($localeEntry['relationships']); } } else { diff --git a/src/Distilleries/Contentful/Webhook/EntryHandler.php b/src/Distilleries/Contentful/Webhook/EntryHandler.php index 7677d58..1ea38d1 100755 --- a/src/Distilleries/Contentful/Webhook/EntryHandler.php +++ b/src/Distilleries/Contentful/Webhook/EntryHandler.php @@ -159,7 +159,7 @@ protected function upsertEntry($payload) { $locales = Locale::all(); $locales = is_array($locales) ? collect($locales) : $locales; - $this->entries->toContentfulModel($payload,$locales); + $this->entries->toContentfulModel($payload, $locales); } /** diff --git a/src/database/migrations/2018_06_05_143736_create_entry_relationships_table.php b/src/database/migrations/2018_06_05_143736_create_entry_relationships_table.php index 2b81ff0..6ee8aac 100755 --- a/src/database/migrations/2018_06_05_143736_create_entry_relationships_table.php +++ b/src/database/migrations/2018_06_05_143736_create_entry_relationships_table.php @@ -16,19 +16,19 @@ public function up() Schema::create('entry_relationships', function (Blueprint $table) { $table->string('locale', 16); $table->string('country', 16); - $table->string('source_contentful_id')->index(); - $table->string('source_contentful_type')->index(); - $table->string('related_contentful_id')->index(); - $table->string('related_contentful_type')->index(); + $table->string('source_contentful_id', 64)->index(); + $table->string('source_contentful_type', 64)->index(); + $table->string('related_contentful_id', 64)->index(); + $table->string('related_contentful_type', 64)->index(); $table->integer('order')->unsigned()->default(0); - $table->index(['locale', 'source_contentful_id'], 'locale_source_contentful_id_index'); - $table->index(['country','locale', 'source_contentful_id'], 'cl_source_contentful_id_index'); - $table->index(['locale', 'source_contentful_id', 'related_contentful_id', 'related_contentful_type'], 'locale_source_related_index'); - $table->index(['country','locale', 'source_contentful_id', 'related_contentful_id', 'related_contentful_type'], 'cl_source_related_index'); - $table->index(['locale', 'related_contentful_id'], 'locale_related_contentful_id_index'); - $table->index(['country','locale', 'related_contentful_id'], 'cl_related_contentful_id_index'); - $table->index(['country','locale', 'related_contentful_id', 'source_contentful_id', 'source_contentful_type'], 'cl_related_source_index'); + $table->index(['locale', 'source_contentful_id'], 'l_sid_idx'); + $table->index(['country', 'locale', 'source_contentful_id'], 'c_l_sid_idx'); + $table->index(['locale', 'source_contentful_id', 'related_contentful_id', 'related_contentful_type'], 'l_sid_rid_rty_idx'); + $table->index(['country', 'locale', 'source_contentful_id', 'related_contentful_id', 'related_contentful_type'], 'c_l_sid_rid_rty_idx'); + $table->index(['locale', 'related_contentful_id'], 'l_rid_idx'); + $table->index(['country', 'locale', 'related_contentful_id'], 'c_l_rid_idx'); + $table->index(['country', 'locale', 'related_contentful_id', 'source_contentful_id', 'source_contentful_type'], 'c_l_rid_sid_sty_idx'); }); } diff --git a/src/database/migrations/2018_07_17_143442_add_country_from_locales_table.php b/src/database/migrations/2018_07_17_143442_add_country_from_locales_table.php index 6a59a36..924788d 100755 --- a/src/database/migrations/2018_07_17_143442_add_country_from_locales_table.php +++ b/src/database/migrations/2018_07_17_143442_add_country_from_locales_table.php @@ -28,6 +28,9 @@ public function down() { Schema::table('locales', function (Blueprint $table) { $table->dropColumn('country'); + }); + + Schema::table('locales', function (Blueprint $table) { $table->dropColumn('locale'); }); } diff --git a/src/database/migrations/2018_08_13_100626_create_releases_table.php b/src/database/migrations/2018_08_13_100626_create_releases_table.php index b8ab1f2..60c2dd6 100755 --- a/src/database/migrations/2018_08_13_100626_create_releases_table.php +++ b/src/database/migrations/2018_08_13_100626_create_releases_table.php @@ -13,7 +13,7 @@ class CreateReleasesTable extends Migration */ public function up() { - Schema::create('releases', function(Blueprint $table) { + Schema::create('releases', function (Blueprint $table) { $table->increments('id'); $table->integer('current')->unsigned()->default(0); $table->timestamps(); diff --git a/tests/ContentfulTestCase.php b/tests/ContentfulTestCase.php index 296e163..d522680 100755 --- a/tests/ContentfulTestCase.php +++ b/tests/ContentfulTestCase.php @@ -55,4 +55,4 @@ public function assertHTTPExceptionStatus($expectedStatusCode, Closure $statusCo sprintf("Expected an HTTP status of %d but got %d.", $expectedStatusCode, $code) ); } -} \ No newline at end of file +} diff --git a/tests/Distilleries/Contentful/Helpers/CasterTest.php b/tests/Distilleries/Contentful/Helpers/CasterTest.php index 2f751e2..7f3187d 100755 --- a/tests/Distilleries/Contentful/Helpers/CasterTest.php +++ b/tests/Distilleries/Contentful/Helpers/CasterTest.php @@ -11,57 +11,57 @@ public function testIsString() public function testToJson() { - $data = ['name' => 'John', 'city' => 'Paris', 'age' => '23']; + $data = ['name' => 'John', 'city' => 'Paris', 'age' => '23']; - $this->assertEquals(\Distilleries\Contentful\Helpers\Caster::toJson($data), json_encode($data)); + $this->assertEquals(\Distilleries\Contentful\Helpers\Caster::toJson($data), json_encode($data)); } public function testFromJson() { - $data = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; + $data = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; - $this->assertEquals(\Distilleries\Contentful\Helpers\Caster::fromJson($data), json_decode($data, true)); + $this->assertEquals(\Distilleries\Contentful\Helpers\Caster::fromJson($data), json_decode($data, true)); } public function testFromJsonEmpty() { - $data = ''; + $data = ''; - $this->assertEquals(\Distilleries\Contentful\Helpers\Caster::fromJson($data), null); + $this->assertEquals(\Distilleries\Contentful\Helpers\Caster::fromJson($data), null); } public function testFromJsonErrorNone() { - $data = '{"a":1;"b":2}'; + $data = '{"a":1;"b":2}'; - $this->assertEquals(\Distilleries\Contentful\Helpers\Caster::fromJson($data), null); + $this->assertEquals(\Distilleries\Contentful\Helpers\Caster::fromJson($data), null); } public function testMarkdown() { - $md = '#test'; + $md = '#test'; - $this->assertEquals(\Distilleries\Contentful\Helpers\Caster::markdown($md), '