Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.1 #34

Merged
merged 6 commits into from
Dec 14, 2019
Merged

2.1 #34

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ composer.lock
.env
.DS_Store
/.vscode
.phpunit.result.cache
dump.rdb
Empty file modified .styleci.yml
100644 → 100755
Empty file.
1 change: 0 additions & 1 deletion .travis.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: php
php:
- 7.1
- 7.2
- 7.3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add 7.4 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not ready on travis

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw it in laravel/framework

before_script:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All Notable changes to `laravel-visits` will be documented in this file.

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## 2.1.0

- Rewrites huge part of the package to support multiple data engines.
- Adds database's data engine support (Eloquent).


## 2.0.0

- Global ignore feature (can be enabled from [config/visits.php](https://github.com/awssat/laravel-visits/blob/master/src/config/visits.php#L70))
Expand Down
Empty file modified ISSUE_TEMPLATE.md
100644 → 100755
Empty file.
Empty file modified LICENSE.md
100644 → 100755
Empty file.
20 changes: 11 additions & 9 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ Laravel Visits is a counter that can be attached to any model to track its visit

## Features
- A model item can have many types of recorded visits (using tags).
- It's not limited to one type of Model (like some packages that allow only the User model).
- Record per visitors and not by visits using IP detecting, so even with the refresh, visit won't duplicate (can be changed from config).
- Get Top/Lowest visits per model.
- It's not limited to one type of Model (like some packages that allow only User model).
- Record per visitors and not by vistis using IP detecting, so even with refresh, visit won't duplicate (can be changed from config).
- Get Top/Lowest visits per a model.
- Get most visited countries, refs, OSes, and languages.
- Get visits per period of time like a month of a year of an item or model.
- Get visits per a period of time like a month of a year of an item or model.
- Supports multiple data engines: Redis or database (any SQL engine that Eloquent supports).


## Install
To get started with Laravel Visits, use Composer to add the package to your project's dependencies:
Expand All @@ -48,10 +50,10 @@ composer require awssat/laravel-visits
```
#### Requirement
- Laravel 5.5+
- PHP 7.1+
- This package relies heavily on Redis.
To use it, make sure that Redis is configured and ready.
Learn More => [Laravel Redis Configuration](https://laravel.com/docs/5.6/redis#configuration)
- PHP 7.2+
- Data engines options (can be configured from config/visits.php):
- Redis: make sure that Redis is configured and ready. (see [Laravel Redis Configuration](https://laravel.com/docs/5.6/redis#configuration))
- Database: publish migration file: `php artisan vendor:publish --provider="Awssat\Visits\VisitsServiceProvider" --tag="migrations"` then migrate.



Expand All @@ -78,8 +80,8 @@ To prevent any data loss add a new connection on `config/database.php`
```

and you can define your redis connection name on `config/visits.php`

```php

'connection' => 'default' // to 'laravel-visits'
```

Expand Down
28 changes: 16 additions & 12 deletions composer.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,36 @@
}
],
"require": {
"php": "~7.1",
"illuminate/support": "~5.5||^6.0",
"php": "~7.2",
"illuminate/support": "~5.5.0 || ~5.6.0 || ~5.7.0 || ~5.8.0 || ^6.0",
"jaybizzle/crawler-detect": "^1.2",
"predis/predis": "^1.1",
"spatie/laravel-referer": "^1.3",
"torann/geoip": "^1.0"
},
"require-dev": {
"illuminate/database": "~5.5||^6.0",
"orchestra/testbench": "~3.0",
"mockery/mockery": "^0.9.5 || ^1.0",
"fzaninotto/faker": "^1.6",
"doctrine/dbal": "^2.5",
"phpunit/phpunit": "^6.1"
"fzaninotto/faker": "^1.6",
"illuminate/support": "~5.5.0 || ~5.6.0 || ~5.7.0 || ~5.8.0 || ^6.0",
"mockery/mockery": "^1.2",
"orchestra/testbench": "^3.5 || ^3.6 || ^3.7 || ^3.8 || ^4.0",
"predis/predis": "^1.1"
},
"suggest": {
"predis/predis": "Needed if you are using redis as data engine of laravel-visits",
"ext-redis": "Needed if you are using redis as engine data of laravel-visits",
"illuminate/database": "Needed if you are using database as engine data of laravel-visits"
},
"autoload": {
"psr-4": {
"awssat\\Visits\\": "src"
"Awssat\\Visits\\": "src"
},
"files": [
"src/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"awssat\\Visits\\Tests\\": "tests"
"Awssat\\Visits\\Tests\\": "tests"
}
},
"scripts": {
Expand All @@ -57,10 +61,10 @@
},
"laravel": {
"providers": [
"awssat\\Visits\\VisitsServiceProvider"
"Awssat\\Visits\\VisitsServiceProvider"
],
"aliases": {
"Visits": "awssat\\Visits\\Visits"
"Visits": "Awssat\\Visits\\Visits"
}
}
},
Expand Down
37 changes: 37 additions & 0 deletions database/migrations/create_visits_table.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateVisitsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('visits', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('primary_key');
$table->string('secondary_key')->nullable();
$table->unsignedBigInteger('score');
$table->json('list')->nullable();
$table->timestamp('expired_at')->nullable();
$table->timestamps();
$table->unique(['primary_key', 'secondary_key']);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('visits');
}
}
Empty file modified phpunit.xml
100644 → 100755
Empty file.
32 changes: 32 additions & 0 deletions src/Commands/CleanCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Awssat\Visits\Commands;

use Awssat\Visits\Models\Visit;
use Illuminate\Console\Command;

class CleanCommand extends Command
{
protected $signature = 'visits:clean';
protected $description = '(Laravel-Visits) Clean expired keys and visits.';


public function __construct()
{
parent::__construct();
}

public function handle()
{
$currentEngine = config('visits.engine') ?? '';

if($currentEngine == 'eloquent') {
$this->cleanEloquent();
}
}

protected function cleanEloquent()
{
Visit::where('expired_at', '<', \Carbon\Carbon::now())->delete();
}
}
31 changes: 31 additions & 0 deletions src/DataEngines/DataEngine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Awssat\Visits\DataEngines;

Interface DataEngine
{
public function connect(string $connection): self;
public function setPrefix(string $prefix): self;

public function increment(string $key, int $value, ?string $member = null): bool;
public function decrement(string $key, int $value, ?string $member = null): bool;

public function delete($key, ?string $member = null): bool;
public function get(string $key, ?string $member = null);
public function set(string $key, $value, ?string $member = null): bool;

public function flatList(string $key, int $limit): array;
public function addToFlatList(string $key, $value): bool;
public function search(string $word, bool $noPrefix = true): array;
public function valueList(string $search, int $limit = -1, bool $orderByAsc = false, bool $withValues = false): array;


public function exists(string $key): bool;

/**
* @return int seconds, will return -1 if no it has no expiration
*/
public function timeLeft(string $key): int;

public function setExpiration(string $key, int $time): bool;
}
Loading