Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesPong committed Mar 12, 2018
2 parents 28118bc + dabc4a3 commit abe3bcb
Show file tree
Hide file tree
Showing 116 changed files with 4,484 additions and 13,962 deletions.
11 changes: 10 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ ENABLE_VISITOR_LOG=
COMMENT_DRIVER=
DISQUS_SHORT_NAME=

FILESYSTEM_DRIVER=
FILESYSTEM_DRIVER=

ADMIN_EMAIL=

MAIL_FROM_ADDRESS=
MAIL_FROM_NAME=

SCOUT_QUEUE=true
ALGOLIA_APP_ID=
ALGOLIA_SECRET=
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

## 1.0.0 - 2018-03-12
### Added
- Package spatie/laravel-backup and related schedule
- Google Drive storage support ([0ce91e0](https://github.com/MilesPong/indigo/commit/0ce91e02a96b054920259c7a2364512359327867), [9d1169b](https://github.com/MilesPong/indigo/commit/9d1169b1f1227b68a7d8d28b5118604f3544e7d2), [7a98e08](https://github.com/MilesPong/indigo/commit/7a98e0842d18bd00e6995dd562aba03107058aa4))
- New feature **page** support ([37b43f1](https://github.com/MilesPong/indigo/commit/37b43f188a4679cef5adf987e5aca5a902ee9c02))
- Add proper right in viewing unpublished-post from admin ([32cd8a2](https://github.com/MilesPong/indigo/commit/32cd8a28c947607018495f4c019fcd36c6096f04))
- Feature force-delete and restore
- Support of viewing original markdown content ([0281bdf](https://github.com/MilesPong/indigo/commit/0281bdffb65903f38ce316d4709e996ee4988450))
- New feature **search** support ([62e5c62](https://github.com/MilesPong/indigo/commit/62e5c6259ebee4ead12869c54c0dd84bac001c6d))
- New feature **feed** support ([0563cd9](https://github.com/MilesPong/indigo/commit/0563cd9d86e5b863816a7f1f42ad6b723deabd37))
- New feature **archives** support ([73c0aee](https://github.com/MilesPong/indigo/commit/73c0aee6d16478738444f213424d0505a88eae9d))

### Changed
- Refactor counter ([6aa01f3](https://github.com/MilesPong/indigo/commit/6aa01f339faac085ba21ed8ed24cc156d5c59c29))
- Union app's config to indigo.php ([b51efba](https://github.com/MilesPong/indigo/commit/b51efbacb8db3adabe9d4a4999c81f8644b994f9))
- Update `route:logs` with http basic auth
- Make ViewedEventListener run in queue
- Update materialize-css to `alpha4`
- Adjust container's width for small screen

### Removed
- Immature cache ([7b6dbc4](https://github.com/MilesPong/indigo/commit/7b6dbc4e81354e34865627b86ced0fd168e1d244))
- Old Counter
- File `TODO.md`
- File `package-lock.json`

### Fixed
- Sidenav trigger menu ([d105d02](https://github.com/MilesPong/indigo/commit/d105d02c43bea9a1c1c52937d2b7e6100ee8d607))
- Field `is_draft` input
- Query string in table's pagination ([dc1054c](https://github.com/MilesPong/indigo/commit/dc1054ce38aaa7e0f43b43e19d57ae1926a0a232))

## 0.4.0 - 2018-01-29
### Added
- Multiple mix support
Expand Down
36 changes: 0 additions & 36 deletions TODO.md

This file was deleted.

151 changes: 151 additions & 0 deletions app/Console/Commands/SaveCounter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

namespace App\Console\Commands;

use Carbon\Carbon;
use Closure;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Model;
use Indigo\Contracts\Counter;
use Indigo\Contracts\Viewable;

/**
* Class SaveCounter
* @package App\Console\Commands
*/
class SaveCounter extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'counter:save {viewable* : The array of Viewable}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Save posts view count into database and flush cache';
/**
* @var \Indigo\Contracts\Counter
*/
private $counter;
/**
* @var array
*/
private $viewableMaps = [];

/**
* Create a new command instance.
*
* @param \Indigo\Contracts\Counter $counter
*/
public function __construct(Counter $counter)
{
parent::__construct();

$this->counter = $counter;
}

/**
* Execute the console command.
*/
public function handle()
{
$viewableArray = $this->argument('viewable');

// Validate arguments
$this->validate($viewableArray);

$this->iterateViewable(function ($viewable) {
$stats = $this->getStats($viewable);

$this->updateCount($viewable, (array)$stats);

$this->resetStats($viewable);
});
}

/**
* @param $viewableArray
*/
private function validate($viewableArray)
{
foreach ($viewableArray as $className) {
$instance = resolve($className);
if (!$instance instanceof Viewable || !$instance instanceof Model) {
$this->error("{$className} is not implement with " . Viewable::class);
exit;
}
$this->setViewableMaps($className, $instance);
}
}

/**
* @param $name
* @param $instance
* @return $this
*/
private function setViewableMaps($name, $instance)
{
$this->viewableMaps[$name] = $instance;

return $this;
}

/**
* @param \Closure $callback
*/
private function iterateViewable(Closure $callback)
{
foreach ($this->viewableMaps as $instance) {
$callback($instance);
}
}

/**
* @param $key
* @return mixed
*/
private function getStats($key)
{
return $this->counter->getAll($key);
}

/**
* @param \Indigo\Contracts\Viewable|\Illuminate\Database\Eloquent\Model $viewable
* @param array $data
*/
private function updateCount($viewable, array $data = [])
{
$tableData = [];

foreach ($data as $identifier => $increment) {
$viewable->newQuery()->where($viewable->getKeyName(), $identifier)->increment($viewable->getCountField(),
$increment);
array_push($tableData, [$identifier, $increment]);
}

$this->success(get_class($viewable), $tableData);
}

/**
* @param $className
* @param $tableData
*/
private function success($className, $tableData)
{
$this->info("Save count of {$className} successfully at " . Carbon::now()->toDateTimeString());
$this->table(['ID', 'Increment'], $tableData);
}

/**
* @param $viewable
* @return bool
*/
private function resetStats($viewable)
{
return $this->counter->resetAll($viewable);
}
}
126 changes: 0 additions & 126 deletions app/Console/Commands/SavePostViewCount.php

This file was deleted.

8 changes: 5 additions & 3 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console;

use App\Console\Commands\SavePostViewCount;
use App\Console\Commands\SaveCounter;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

Expand All @@ -14,7 +14,6 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
SavePostViewCount::class
];

/**
Expand All @@ -27,7 +26,10 @@ protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
$schedule->command('view_count:save')->hourly()->appendOutputTo(storage_path() . '/logs/cron.log');
$schedule->command(SaveCounter::class)->hourly()->appendOutputTo(storage_path() . '/logs/counter.log');
$schedule->command('backup:clean')->dailyAt('01:00');
$schedule->command('backup:run')->dailyAt('02:00');
$schedule->command('backup:monitor')->twiceMonthly();
}

/**
Expand Down
Loading

0 comments on commit abe3bcb

Please sign in to comment.