Skip to content

Commit

Permalink
Merge 6b2fe15 into 1888c2f
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhenry committed Jan 5, 2016
2 parents 1888c2f + 6b2fe15 commit 4360294
Show file tree
Hide file tree
Showing 175 changed files with 2,926 additions and 1,415 deletions.
6 changes: 3 additions & 3 deletions api/app/Console/Commands/ApiaryValidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public function handle()

exec("$validator $fileLocation", $output, $exitCode);

if ($exitCode == 0) {
$this->info('Apiary Documentation validation passed');
if ($exitCode == 0){
$this->info("Apiary Documentation validation passed");
} else {
$this->error('Apiary Documentation validation failed');
$this->error("Apiary Documentation validation failed");
}

return $exitCode;
Expand Down
43 changes: 43 additions & 0 deletions api/app/Console/Commands/ForumCleanupCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Console\Commands;

use Illuminate\Console\Command;

class ForumCleanupCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'forum:cleanup';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Init of Vanilla Forum & database refresh';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$dir = realpath(base_path() . '/../forum');
exec('composer run-script post-install-cmd --working-dir "' . $dir . '"', $output, $exitCode);

return $exitCode;
}
}
1 change: 1 addition & 0 deletions api/app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Kernel extends ConsoleKernel
'App\Console\Commands\ApiaryValidateCommand',
'App\Console\Commands\GenerateKeysCommand',
'App\Console\Commands\CreateUserCommand',
'App\Console\Commands\ForumCleanupCommand',
];

/**
Expand Down
1 change: 1 addition & 0 deletions api/app/Http/Controllers/AbstractTagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ protected function getPivotValidationRules()
'_pivot.tag_group_parent_id' => 'required|uuid',
];
}

}
3 changes: 3 additions & 0 deletions api/app/Http/Controllers/ArticleCommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

class ArticleCommentController extends PostCommentController
{
protected $permissionsEnabled = true;
protected $defaultRole = false;

/**
* Set dependencies.
*
Expand Down
5 changes: 4 additions & 1 deletion api/app/Http/Controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
class ArticleController extends EntityController
{
use LocalizableTrait;

use TagCategoryTrait;

protected $permissionsEnabled = true;
protected $defaultRole = false;

protected $rootCategoryTagName = \SeedTags::articleGroupTagName;

/**
Expand Down
3 changes: 3 additions & 0 deletions api/app/Http/Controllers/ArticleMetaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class ArticleMetaController extends ChildEntityController
{
protected $relationName = 'metas';

protected $permissionsEnabled = true;
protected $defaultRole = false;

public function __construct(Article $parentModel, EloquentModelTransformer $transformer)
{
parent::__construct($parentModel, $transformer);
Expand Down
3 changes: 3 additions & 0 deletions api/app/Http/Controllers/ArticleSectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

class ArticleSectionController extends AbstractSectionController
{
protected $permissionsEnabled = true;
protected $defaultRole = false;

use LocalizableTrait;

protected $relationName = 'sections';
Expand Down
3 changes: 3 additions & 0 deletions api/app/Http/Controllers/ArticleTagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

class ArticleTagController extends AbstractTagController
{
protected $permissionsEnabled = true;
protected $defaultRole = false;

public function __construct(Article $parentModel, EloquentModelTransformer $transformer)
{
parent::__construct($parentModel, $transformer);
Expand Down
1 change: 1 addition & 0 deletions api/app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public function loginAsUser(Request $request, User $userModel, $userId)
return $this->getResponse()
->transformer($this->getTransformer())
->item($this->auth->generateToken($user));

}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/Traits/TagCategoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getAllTagCategories(Request $request)
{
$collection = $this->getTagsFromRoot($this->getRootTagName());
$collection = $this->getWithNested($collection, $request);
$this->checkPermission(static::class.'@getAllTags', ['model' => $collection]);
$this->checkPermission(static::class.'@getAllTagCategories', ['model' => $collection]);

return $this->getResponse()
->transformer($this->getTransformer())
Expand Down
2 changes: 2 additions & 0 deletions api/app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@
$app->get('images/{id}', ['as' => \App\Models\Image::class, 'uses' => 'ImageController@getOne']);

});


37 changes: 21 additions & 16 deletions api/app/Models/AbstractPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace App\Models;

use App\Models\Traits\CommentableInterface;
use App\Models\Traits\CommentableTrait;
use Illuminate\Database\Eloquent\Collection;
use Rhumsaa\Uuid\Uuid;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -51,9 +53,9 @@
* @property Rating[]|Collection $userRatings
* @property Bookmark[]|Collection $bookmarks
*/
class AbstractPost extends IndexedModel implements LocalizableModelInterface
class AbstractPost extends IndexedModel implements LocalizableModelInterface, CommentableInterface
{
use RevisionableTrait, LocalizableModelTrait, TagTrait, RateableTrait, BookmarkableTrait;
use RevisionableTrait, LocalizableModelTrait, TagTrait, RateableTrait, BookmarkableTrait, CommentableTrait;

const defaultExcerptWordCount = 30;

Expand Down Expand Up @@ -100,6 +102,7 @@ class AbstractPost extends IndexedModel implements LocalizableModelInterface
'status',
'users_can_comment',
'public_access',
'short_title'
];

protected $hidden = ['permalinks'];
Expand All @@ -113,6 +116,8 @@ class AbstractPost extends IndexedModel implements LocalizableModelInterface
'sections_display' => 'json',
];

protected static $permalinkModel = PostPermalink::class;

protected $indexRelations = ['tags', 'permalinks', 'author', 'metas'];

public static function getValidationRules($entityId = null, array $requestEntity = [])
Expand Down Expand Up @@ -190,7 +195,7 @@ public static function boot()
static::bootScope();
static::saving(function (AbstractPost $model) {
if ($model->getOriginal('permalink') !== $model->permalink && ! is_null($model->permalink)) {
$permalink = new PostPermalink(['permalink' => $model->permalink]);
$permalink = new static::$permalinkModel(['permalink' => $model->permalink]);
$permalink->save();
}

Expand All @@ -199,7 +204,7 @@ public static function boot()

static::saved(function (AbstractPost $model) {
if ($model->getOriginal('permalink') !== $model->permalink && ! is_null($model->permalink)) {
$permalink = PostPermalink::findOrFail($model->permalink);
$permalink = call_user_func_array(static::$permalinkModel . '::findOrFail', [$model->permalink]);
$model->permalinks()->save($permalink);
}

Expand Down Expand Up @@ -247,7 +252,7 @@ public function findByIdentifier($id)
} catch (ModelNotFoundException $e) { //id or permalink not found, try permalink history
$name = class_basename($this);

return PostPermalink::findOrFail($id)->{$name};
return call_user_func_array(static::$permalinkModel . '::findOrFail', [$id])->{$name};
}
}

Expand Down Expand Up @@ -276,24 +281,14 @@ public function getExcerptAttribute($excerpt)

public function permalinks()
{
return $this->hasMany(PostPermalink::class, 'post_id', 'post_id');
return $this->hasMany(static::$permalinkModel, 'post_id', 'post_id');
}

public function metas()
{
return $this->morphMany(Meta::class, 'metaable');
}

/**
* Get comment relationship.
*
* @return PostDiscussion
*/
public function comments()
{
return (new PostDiscussion())->setPost($this);
}

public function thumbnailImage()
{
return $this->hasOne(Image::class, 'image_id', 'thumbnail_image_id');
Expand All @@ -316,4 +311,14 @@ public function setPostTypeAttribute()
{
throw new \InvalidArgumentException('No direct attribute assignment');
}

public function getTitle()
{
return $this->title;
}

public function getExcerpt()
{
return $this->excerpt;
}
}
1 change: 1 addition & 0 deletions api/app/Models/PostComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ public static function find($id, $columns = ['*'])
{
return;
}

}
19 changes: 10 additions & 9 deletions api/app/Models/PostDiscussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace App\Models;

use App;
use App\Models\Traits\CommentableInterface;
use App\Services\Api\Vanilla\Client as VanillaClient;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Spira\Core\Model\Collection\Collection;
Expand Down Expand Up @@ -58,10 +59,10 @@ public static function getValidationRules($entityId = null, array $requestEntity
public function createDiscussion()
{
$this->getClient()->api('discussions')->create(
$this->post->title,
$this->post->excerpt,
$this->post->getTitle(),
$this->post->getExcerpt(),
1,
['ForeignID' => $this->post->post_id]
['ForeignID' => $this->post->getKey()]
);
}

Expand All @@ -73,7 +74,7 @@ public function createDiscussion()
public function deleteDiscussion()
{
$this->getClient()->api('discussions')->removeByForeignId(
$this->post->post_id
$this->post->getKey()
);
}

Expand All @@ -85,7 +86,7 @@ public function deleteDiscussion()
protected function getDiscussionId()
{
$discussion = $this->getClient()->api('discussions')->findByForeignId(
$this->post->post_id
$this->post->getKey()
);

return $discussion['Discussion']['DiscussionID'];
Expand Down Expand Up @@ -151,11 +152,11 @@ public function getRelated()
public function getResults()
{
// First a minimal call to the discussion for the total comment count
$discussion = $this->getDiscussion($this->post->post_id, 1);
$discussion = $this->getDiscussion($this->post->getKey(), 1);
$count = $discussion['Discussion']['CountComments'];

// Now get the entire batch of comments
$discussion = $this->getDiscussion($this->post->post_id, $count);
$discussion = $this->getDiscussion($this->post->getKey(), $count);

// And turn them into a collection of models
$comments = $this->prepareCommentsForHydrate($discussion['Comments']);
Expand Down Expand Up @@ -321,11 +322,11 @@ public function match(array $models, Collection $results, $relation)
/**
* Sets the post the discussion belongs to.
*
* @param AbstractPost $post
* @param $post
*
* @return $this
*/
public function setPost(AbstractPost $post)
public function setPost($post)
{
$this->post = $post;

Expand Down
2 changes: 0 additions & 2 deletions api/app/Models/PostPermalink.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class PostPermalink extends BaseModel

protected static $validationRules = [
'permalink' => 'string|required',
'check_entity_id' => 'uuid',
'value' => 'required|string',
];

public function article()
Expand Down
1 change: 1 addition & 0 deletions api/app/Models/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ public static function getContentTypes()
{
return array_keys(self::$contentTypeMap);
}

}
12 changes: 7 additions & 5 deletions api/app/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Tag extends IndexedModel
protected $mappingProperties = [
'tag_id' => [
'type' => 'string',
'index' => 'no',
'index' => 'no'
],
'tag' => [
'type' => 'string',
Expand All @@ -52,9 +52,10 @@ class Tag extends IndexedModel

public function articles()
{
return $this->belongsToMany(Article::class, 'post_tag', 'tag_id', 'post_id', 'articles')->withPivot('tag_group_id', 'tag_group_parent_id');
return $this->getBelongsRelation(Article::class, 'post_tag', null, 'post_id');
}


/**
* @param mixed $id
* @return BaseModel
Expand All @@ -79,7 +80,8 @@ public function findByIdentifier($id)
public static function getGroupedTagPivots(Collection $tags, $parentTagName, array $tagDefinition = null)
{
if (! $tagDefinition) {
$tagDefinition = SeedTags::$tagHierarchy[$parentTagName];
$seededTags = SeedTags::getSeedTags();
$tagDefinition = $seededTags[$parentTagName];
}

array_walk($tagDefinition['children'], function (&$value, $key) {
Expand Down Expand Up @@ -130,8 +132,8 @@ public function parentTags()
]);
}

protected function getBelongsRelation($related, $relation)
protected function getBelongsRelation($related, $table = null, $foreignKey = null, $otherKey = null)
{
return $this->belongsToMany($related, null, null, null, $relation)->withPivot('tag_group_id', 'tag_group_parent_id');
return $this->belongsToMany($related, $table, $foreignKey, $otherKey)->withPivot('tag_group_id', 'tag_group_parent_id');
}
}
2 changes: 1 addition & 1 deletion api/app/Models/Traits/BookmarkableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace App\Models\Traits;

use App\Models\Bookmark;
use Spira\Model\Model\BaseModel;
use Spira\Core\Model\Model\BaseModel;

trait BookmarkableTrait
{
Expand Down
Loading

0 comments on commit 4360294

Please sign in to comment.