Skip to content

Commit

Permalink
build(core): initial
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbmaulana committed Nov 13, 2023
0 parents commit 42bdcb6
Show file tree
Hide file tree
Showing 38 changed files with 1,646 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Laravel.php Log

on: push

jobs:
cd:
runs-on: ubuntu-latest
steps:
- name: cd
uses: tripteki/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
repotoken: ${{ secrets.REPOSITORY_TOKEN }}
repouser: tripteki
repository: https://packagist.org
language: php
artifact: composer.json
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Trip Teknologi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<h1 align="center">Log</h1>

This package provides implementation of Auth Activity Log in repository pattern for Lumen and Laravel besides REST API starterpack of admin management with no intervention to codebase and keep clean.

Getting Started
---

Installation :

```
$ composer require tripteki/laravelphp-log
```

How to use it :

- Read detail optional instruction here [Log](https://spatie.be/docs/laravel-activitylog/v4/installation-and-setup).

- Put `Tripteki\Log\Traits\LogTrait` to any of your model loggable then optionally you can configure `protected static` of `$recordName`, `$recordEvents`, and `$recordLists`.

- Put `Tripteki\Log\Providers\LogServiceProvider` to service provider configuration list.

- Put `Tripteki\Log\Providers\LogServiceProvider::ignoreConfig()` into `register` provider, then publish config file into your project's directory with running :

```
php artisan vendor:publish --tag=tripteki-laravelphp-log
```

- Put `Tripteki\Log\Providers\LogServiceProvider::ignoreMigrations()` into `register` provider, then publish migrations file into your project's directory with running (optionally) :

```
php artisan vendor:publish --tag=tripteki-laravelphp-log-migrations
```

- Migrate.

```
$ php artisan migrate
```

- Emit Event-Listener.

```
php artisan queue:work
```

- Publish tests file into your project's directory with running (optionally) :

```
php artisan vendor:publish --tag=tripteki-laravelphp-log-tests
```

- Sample :

```php
use Tripteki\Log\Contracts\Repository\Admin\ILogRepository as ILogAdminRepository;
use Tripteki\Log\Contracts\Repository\ILogRepository;

$logAdminRepository = app(ILogAdminRepository::class);

// $logAdminRepository->get(5); //
// $logAdminRepository->all(); //

$repository = app(ILogRepository::class);
// $repository->setUser(...); //
// $repository->getUser(); //

// $repository->archive(5); //
// $repository->unarchive(5); //
// $repository->get(5); //
// $repository->all(); //
```

- Generate swagger files into your project's directory with putting this into your annotation configuration (optionally) :

```
base_path("app/Http/Controllers/Log")
```

```
base_path("app/Http/Controllers/Admin/Log")
```

Usage
---

`php artisan adminer:install:log`

Author
---

- Trip Teknologi ([@tripteki](https://linkedin.com/company/tripteki))
- Hasby Maulana ([@hsbmaulana](https://linkedin.com/in/hsbmaulana))
57 changes: 57 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "tripteki/laravelphp-log",
"version": "1.0.0",
"description": "Trip Teknologi's Laravel.php Logs",

"readme": "README.md",
"license": "MIT",
"authors": [ { "name": "Trip Teknologi", "email": "[email protected]" } ],
"homepage": "https://github.com/tripteki/laravelphp-log",
"support": { "issues": "https://github.com/tripteki/laravelphp-log/issues" },

"require": {

"php": "^8.0.2",

"tripteki/laravelphp-repository": "^1.0.0",
"tripteki/laravelphp-helpers": "^1.0.0",
"tripteki/laravelphp-adminer": "^1.0.0",
"tripteki/laravelphp-import-export": "^1.0.0",
"tripteki/laravelphp-request-response-query": "^1.0.0",

"spatie/laravel-activitylog": "^4.7.2"
},

"require-dev": {},

"suggest": {

"laravel/lumen-framework": "Required when using lumen framework (^9.0).",
"laravel/framework": "Required when using laravel framework (^9.0)."
},

"autoload": {

"psr-4": {

"Tripteki\\Log\\": "src/"
}
},

"autoload-dev": {},

"extra": {

"laravel": {

"dont-discover": [],

"providers": [

"Tripteki\\Log\\Providers\\LogServiceProvider"
],

"aliases": []
}
}
}
18 changes: 18 additions & 0 deletions config/log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

return [

"enabled" => true,

"default_log_name" => "log",

"activity_model" => Tripteki\Log\Models\Admin\Log::class,
"table_name" => "logs",
"database_connection" => null,

"default_auth_driver" => null,

"subject_returns_soft_deleted_models" => false,

"delete_records_older_than_days" => 365,
];
73 changes: 73 additions & 0 deletions database/migrations/2023_01_20_000000_create_logs_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Tripteki\Helpers\Contracts\AuthModelContract;
use Tripteki\Log\Providers\LogServiceProvider;

class CreateLogsTable extends Migration
{
/**
* @var string
*/
protected $keytype;

/**
* @return void
*/
public function __construct()
{
$this->keytype = app(AuthModelContract::class)->getKeyType();
}

/**
* @return void
*/
public function up()
{
$keytype = $this->keytype;

Schema::connection(config("activitylog.database_connection"))->create(config("activitylog.table_name"), function (Blueprint $table) use ($keytype) {

$table->uuid("id");
$table->string("log_name")->nullable();
$table->text("description");

if (! LogServiceProvider::shouldSubjectUid()) {

$table->nullableMorphs("subject", "subject");

} else {

$table->nullableUuidMorphs("subject", "subject");
}

if ($keytype == "int") {

$table->nullableMorphs("causer", "causer");

} else if ($keytype == "string") {

$table->nullableUuidMorphs("causer", "causer");
}

$table->uuid("batch_uuid")->nullable();
$table->json("properties")->nullable();
$table->string("event")->nullable();
$table->timestamps();
$table->softDeletes();

$table->primary("id");
$table->index("log_name");
});
}

/**
* @return void
*/
public function down()
{
Schema::connection(config("activitylog.database_connection"))->dropIfExists(config("activitylog.table_name"));
}
};
78 changes: 78 additions & 0 deletions src/Console/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Tripteki\Log\Console\Commands;

use Tripteki\Helpers\Contracts\AuthModelContract;
use Tripteki\Helpers\Helpers\ProjectHelper;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Console\Command;

class InstallCommand extends Command
{
/**
* @var string
*/
protected $signature = "adminer:install:log";

/**
* @var string
*/
protected $description = "Install the log stack";

/**
* @var \Tripteki\Helpers\Helpers\ProjectHelper
*/
protected $helper;

/**
* @param \Tripteki\Helpers\Helpers\ProjectHelper $helper
* @return void
*/
public function __construct(ProjectHelper $helper)
{
parent::__construct();

$this->helper = $helper;
}

/**
* @return int
*/
public function handle()
{
$this->installStack();

return 0;
}

/**
* @return int|null
*/
protected function installStack()
{
(new Filesystem)->ensureDirectoryExists(base_path("routes/user"));
(new Filesystem)->ensureDirectoryExists(base_path("routes/admin"));
(new Filesystem)->copy(__DIR__."/../../../stubs/routes/user/log.php", base_path("routes/user/log.php"));
(new Filesystem)->copy(__DIR__."/../../../stubs/routes/admin/log.php", base_path("routes/admin/log.php"));
$this->helper->putRoute("api.php", "user/log.php");
$this->helper->putRoute("api.php", "admin/log.php");

(new Filesystem)->ensureDirectoryExists(app_path("Http/Controllers/Log"));
(new Filesystem)->copyDirectory(__DIR__."/../../../stubs/app/Http/Controllers/Log", app_path("Http/Controllers/Log"));
(new Filesystem)->ensureDirectoryExists(app_path("Http/Requests/Logs"));
(new Filesystem)->copyDirectory(__DIR__."/../../../stubs/app/Http/Requests/Logs", app_path("Http/Requests/Logs"));
(new Filesystem)->ensureDirectoryExists(app_path("Http/Controllers/Admin/Log"));
(new Filesystem)->copyDirectory(__DIR__."/../../../stubs/app/Http/Controllers/Admin/Log", app_path("Http/Controllers/Admin/Log"));
(new Filesystem)->ensureDirectoryExists(app_path("Imports/Logs"));
(new Filesystem)->copyDirectory(__DIR__."/../../../stubs/app/Imports/Logs", app_path("Imports/Logs"));
(new Filesystem)->ensureDirectoryExists(app_path("Exports/Logs"));
(new Filesystem)->copyDirectory(__DIR__."/../../../stubs/app/Exports/Logs", app_path("Exports/Logs"));
(new Filesystem)->ensureDirectoryExists(app_path("Http/Requests/Admin/Logs"));
(new Filesystem)->copyDirectory(__DIR__."/../../../stubs/app/Http/Requests/Admin/Logs", app_path("Http/Requests/Admin/Logs"));
(new Filesystem)->ensureDirectoryExists(app_path("Http/Responses"));

$this->helper->putTrait($this->helper->classToFile(get_class(app(AuthModelContract::class))), \Tripteki\Log\Traits\LogCauseTrait::class);

$this->info("Adminer Log scaffolding installed successfully.");
}
};
11 changes: 11 additions & 0 deletions src/Contracts/Repository/Admin/ILogRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Tripteki\Log\Contracts\Repository\Admin;

use Tripteki\Repository\Contracts\Allable;
use Tripteki\Repository\Contracts\Getable;

interface ILogRepository extends Allable, Getable
{
//
};
12 changes: 12 additions & 0 deletions src/Contracts/Repository/ILogRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Tripteki\Log\Contracts\Repository;

use Tripteki\Repository\Contracts\Allable;
use Tripteki\Repository\Contracts\Getable;
use Tripteki\Repository\Contracts\Deleteable;

interface ILogRepository extends Allable, Getable, Deleteable
{
//
};
Loading

0 comments on commit 42bdcb6

Please sign in to comment.