!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 

uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/var/www/html/laravel-crm/vendor/maatwebsite/excel/src/Imports/Persistence/   drwxrwxrwx
Free 12.99 GB of 57.97 GB (22.41%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     CascadePersistManager.php (2.81 KB)      -rw-rw-rw-
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php

namespace Maatwebsite\Excel\Imports\Persistence;

use 
Illuminate\Database\Eloquent\Model;
use 
Illuminate\Database\Eloquent\Relations\BelongsTo;
use 
Illuminate\Database\Eloquent\Relations\BelongsToMany;
use 
Illuminate\Support\Collection;
use 
Maatwebsite\Excel\Transactions\TransactionHandler;

/** @todo  */
class CascadePersistManager
{
    
/**
     * @var TransactionHandler
     */
    
private $transaction;

    
/**
     * @param  TransactionHandler  $transaction
     */
    
public function __construct(TransactionHandler $transaction)
    {
        
$this->transaction $transaction;
    }

    
/**
     * @param  Model  $model
     * @return bool
     */
    
public function persist(Model $model): bool
    
{
        return (
$this->transaction)(function () use ($model) {
            return 
$this->save($model);
        });
    }

    
/**
     * @param  Model  $model
     * @return bool
     */
    
private function save(Model $model): bool
    
{
        if (!
$model->save()) {
            return 
false;
        }

        foreach (
$model->getRelations() as $relationName => $models) {
            
$models array_filter(
                
$models instanceof Collection $models->all() : [$models]
            );

            
$relation $model->{$relationName}();

            if (
$relation instanceof BelongsTo) {
                if (!
$this->persistBelongsTo($relation$models)) {
                    return 
false;
                }
            }

            if (
$relation instanceof BelongsToMany) {
                if (!
$this->persistBelongsToMany($relation$models)) {
                    return 
false;
                }
            }
        }

        
// We need to save the model again to
        // make sure all updates are performed.
        
$model->save();

        return 
true;
    }

    
/**
     * @param  BelongsTo  $relation
     * @param  array  $models
     * @return bool
     */
    
private function persistBelongsTo(BelongsTo $relation, array $models): bool
    
{
        
// With belongs to, we first need to save all relations,
        // so we can use their foreign key to attach to the relation.
        
foreach ($models as $model) {
            
// Cascade any relations that this child model may have.
            
if (!$this->save($model)) {
                return 
false;
            }

            
$relation->associate($model);
        }

        return 
true;
    }

    
/**
     * @param  BelongsToMany  $relation
     * @param  array  $models
     * @return bool
     */
    
private function persistBelongsToMany(BelongsToMany $relation, array $models): bool
    
{
        foreach (
$models as $model) {
            
$relation->save($model);

            
// Cascade any relations that this child model may have.
            
if (!$this->save($model)) {
                return 
false;
            }
        }

        return 
true;
    }
}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ ok ]

:: Make Dir ::
 
[ ok ]
:: Make File ::
 
[ ok ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0062 ]--