Merge branch 'release/0.5.20'

This commit is contained in:
Jonny Barnes 2017-06-30 14:47:33 +01:00
commit 6dca486a75
14 changed files with 166 additions and 74 deletions

View file

@ -52,5 +52,3 @@ TWITTER_ACCESS_TOKEN_SECRET=
SCOUT_DRIVER=pgsql
PIWIK=false
PSYSH_CONFIG=tinker.config.php

3
.psysh.php Normal file
View file

@ -0,0 +1,3 @@
<?php
\Spatie\TinkerTools\ShortClassNames::register();

View file

@ -38,6 +38,10 @@ matrix:
- php: nightly
before_install:
- cp .env.travis .env
- echo 'error_log = "/tmp/php.error.log"' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- psql -U travis -c 'create database travis_ci_test'
- psql -U travis -d travis_ci_test -c 'create extension postgis'
- mkdir travis-phantomjs
- wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O $PWD/travis-phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
- tar -xvf $PWD/travis-phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis-phantomjs
@ -51,10 +55,6 @@ install:
- travis/install-nginx.sh
before_script:
- echo 'error_log = "/tmp/php.error.log"' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- psql -U travis -c 'create database travis_ci_test'
- psql -U travis -d travis_ci_test -c 'create extension postgis'
- cp .env.travis .env
- php artisan key:generate
- php artisan migrate
- php artisan db:seed

View file

@ -76,6 +76,20 @@ class Place extends Model
return $query->where($field, '<=', $distance)->orderBy($field);
}
public function scopeWhereExternalURL(Builder $query, string $url)
{
$type = $this->getType($url);
if ($type === null) {
// we havent set a type, therefore result must be empty set
// id cant be null, so this will return empty set
return $query->whereNull('id');
}
return $query->where('external_urls', '@>', json_encode([
$type => $url,
]));
}
/**
* Get the latitude from the `location` property.
*
@ -115,4 +129,31 @@ class Place extends Model
{
return config('app.shorturl') . '/places/' . $this->slug;
}
public function setExternalUrlsAttribute($url)
{
$type = $this->getType($url);
if ($type === null) {
throw new \Exception('Unkown external url type ' . $url);
}
$already = [];
if (array_key_exists('external_urls', $this->attributes)) {
$already = json_decode($this->attributes['external_urls'], true);
}
$already[$type] = $url;
$this->attributes['external_urls'] = json_encode($already);
}
private function getType(string $url): ?string
{
$host = parse_url($url, PHP_URL_HOST);
if (ends_with($host, 'foursquare.com') === true) {
return 'foursquare';
}
if (ends_with($host, 'openstreetmap.org') === true) {
return 'osm';
}
return null;
}
}

View file

@ -46,10 +46,10 @@ class PlaceService
public function createPlaceFromCheckin(array $checkin): Place
{
//check if the place exists if from swarm
if (array_key_exists('url', $checkin['properties']) && ends_with(parse_url($checkin['properties']['url'][0], PHP_URL_HOST), 'foursquare.com')) {
$place = Place::where('foursquare', $checkin['properties']['url'][0])->get();
if (array_key_exists('url', $checkin['properties'])) {
$place = Place::whereExternalURL($checkin['properties']['url'][0])->get();
if (count($place) === 1) {
return $place;
return $place->first();
}
}
if (array_key_exists('name', $checkin['properties']) === false) {
@ -60,9 +60,7 @@ class PlaceService
}
$place = new Place();
$place->name = $checkin['properties']['name'][0];
if (ends_with(parse_url($checkin['properties']['url'][0], PHP_URL_HOST), 'foursquare.com')) {
$place->foursquare = $checkin['properties']['url'][0];
}
$place->external_urls = $checkin['properties']['url'][0];
$place->location = new Point(
(float) $checkin['properties']['latitude'][0],
(float) $checkin['properties']['longitude'][0]

View file

@ -1,5 +1,8 @@
# Changelog
## Version 0.5.20 (2017-06-30)
- Transition to using a JSON column for external urls of places
## Version 0.5.19 (2017-06-27)
- Fix error in App\\WebMention.php

View file

@ -25,6 +25,7 @@
"predis/predis": "~1.0",
"ramsey/uuid": "^3.5",
"sensiolabs/security-checker": "^4.0",
"spatie/laravel-tinker-tools": "^1.0",
"thujohn/twitter": "~2.0"
},
"require-dev": {

73
composer.lock generated
View file

@ -4,20 +4,20 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "af5dc6e36b50396acecb6c17d3392645",
"content-hash": "17da475fc29dcd3b362b3e0d21c312d9",
"packages": [
{
"name": "aws/aws-sdk-php",
"version": "3.30.1",
"version": "3.30.2",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
"reference": "d234cb5e111945eb4bfca7eda0eef07a25750b29"
"reference": "20539a38dc643a2700f80ae8647dbd1a05d3f7a9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/d234cb5e111945eb4bfca7eda0eef07a25750b29",
"reference": "d234cb5e111945eb4bfca7eda0eef07a25750b29",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/20539a38dc643a2700f80ae8647dbd1a05d3f7a9",
"reference": "20539a38dc643a2700f80ae8647dbd1a05d3f7a9",
"shasum": ""
},
"require": {
@ -84,7 +84,7 @@
"s3",
"sdk"
],
"time": "2017-06-22T22:40:58+00:00"
"time": "2017-06-23T18:54:40+00:00"
},
{
"name": "barnabywalters/mf-cleaner",
@ -2728,16 +2728,16 @@
},
{
"name": "psy/psysh",
"version": "v0.8.7",
"version": "v0.8.8",
"source": {
"type": "git",
"url": "https://github.com/bobthecow/psysh.git",
"reference": "be969b9dc89dcaefdb9a3117fa91fa38bca19f50"
"reference": "fe65c30cbc55c71e61ba3a38b5a581149be31b8e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bobthecow/psysh/zipball/be969b9dc89dcaefdb9a3117fa91fa38bca19f50",
"reference": "be969b9dc89dcaefdb9a3117fa91fa38bca19f50",
"url": "https://api.github.com/repos/bobthecow/psysh/zipball/fe65c30cbc55c71e61ba3a38b5a581149be31b8e",
"reference": "fe65c30cbc55c71e61ba3a38b5a581149be31b8e",
"shasum": ""
},
"require": {
@ -2797,7 +2797,7 @@
"interactive",
"shell"
],
"time": "2017-06-20T12:51:31+00:00"
"time": "2017-06-24T06:16:19+00:00"
},
{
"name": "ramsey/uuid",
@ -2926,6 +2926,57 @@
"description": "A security checker for your composer.lock",
"time": "2017-03-31T14:50:32+00:00"
},
{
"name": "spatie/laravel-tinker-tools",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-tinker-tools.git",
"reference": "4674f9a3d874c8ad488e25ffb7cd936bb7348e43"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-tinker-tools/zipball/4674f9a3d874c8ad488e25ffb7cd936bb7348e43",
"reference": "4674f9a3d874c8ad488e25ffb7cd936bb7348e43",
"shasum": ""
},
"require": {
"illuminate/support": "5.3.*|5.4.*",
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Spatie\\TinkerTools\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
}
],
"description": "Flysystem Adapter for the Dropbox v2 API",
"homepage": "https://github.com/spatie/laravel-tinker-tools",
"keywords": [
"Flysystem",
"api",
"dropbox",
"laravel-tinker-tools",
"spatie",
"v2"
],
"time": "2017-05-22T11:30:34+00:00"
},
{
"name": "swiftmailer/swiftmailer",
"version": "v5.4.8",

View file

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class UpdatePlacesTableAddExternalUrls extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('places', function (Blueprint $table) {
$table->jsonb('external_urls')->nullable();
$table->index('external_urls');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('places', function (Blueprint $table) {
$table->dropIndex('places_external_urls_index');
$table->dropColumn('external_urls');
});
}
}

View file

@ -1,6 +1,8 @@
<?php
use App\Place;
use Illuminate\Database\Seeder;
use Phaza\LaravelPostgis\Geometries\Point;
class PlacesTableSeeder extends Seeder
{
@ -11,13 +13,12 @@ class PlacesTableSeeder extends Seeder
*/
public function run()
{
DB::table('places')->insert([
'name' => 'The Bridgewater Pub',
'slug' => 'the-bridgewater-pub',
'description' => 'A lovely local pub with a decent selection of cask ales',
'location' => 'POINT(-2.3805 53.4983)',
'created_at' => '2016-01-12 16:19:00',
'updated_at' => '2016-01-12 16:19:00',
]);
$place = new Place();
$place->name = 'The Bridgewater Pub';
$place->description = 'A lovely local pub with a decent selection of cask ales';
$place->location = new Point('53.4983', '-2.3805');
$place->external_urls = 'https://foursquare.com/v/123435/the-bridgewater-pub';
$place->external_urls = 'https://www.openstreetmap.org/way/987654';
$place->save();
}
}

6
package-lock.json generated
View file

@ -4329,9 +4329,9 @@
}
},
"webStorage": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/webStorage/-/webStorage-1.2.3.tgz",
"integrity": "sha1-CHN87eWk2ouophKKYoQHB0Cwxxg="
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/webStorage/-/webStorage-1.2.4.tgz",
"integrity": "sha1-/jNN8N5uLe58i9A2uxVaw115FTY="
},
"webworkify": {
"version": "1.4.0",

View file

@ -9,7 +9,7 @@
"mapbox-gl": "^0.38.0",
"marked": "^0.3.6",
"normalize.css": "^7.0.0",
"webStorage": "^1.2.3"
"webStorage": "^1.2.4"
},
"devDependencies": {
"babel-cli": "^6.18.0",

View file

@ -44,7 +44,7 @@ class SwarmTest extends TestCase
->assertStatus(201)
->assertJson(['response' => 'created']);
$this->assertDatabaseHas('places', [
'foursquare' => 'https://foursquare.com/v/123456'
'external_urls' => '{"foursquare": "https://foursquare.com/v/123456"}'
]);
$this->assertDatabaseHas('notes', [
'swarm_url' => 'https://www.swarmapp.com/checkin/abc'

View file

@ -1,38 +0,0 @@
<?php
/**
* Automatically alias Laravel Model's to their base classname.
* Ex: "App\Models\User" now can just be accessed by "User"
*/
if (! function_exists('aliasModels')) {
function aliasModels() {
$finder = new \Symfony\Component\Finder\Finder();
$finder->files()->name('*.php')->in(base_path().'/app');
foreach ($finder as $file) {
$namespace = 'App\\';
if ($relativePath = $file->getRelativePath()) {
$namespace .= strtr($relativePath, '/', '\\') . '\\';
}
$class = $namespace . $file->getBasename('.php');
try {
$r = new \ReflectionClass($class);
if ($r->isSubclassOf('Illuminate\\Database\\Eloquent\\Model')) {
class_alias($class, $file->getBasename('.php'));
}
} catch (Exception $e) {
//
}
}
}
}
aliasModels();
return [
'startupMessage' => '<info>Using local config file (tinker.config.php)</info>',
'commands' => [
// new \App\Tinker\TestCommand,
],
];