Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Soon/AdminLogger/Model/ResourceModel/Log/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/old/app/code/Soon/AdminLogger/Model/ResourceModel/Log/Collection.php
<?php
/**
 * @license http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * @author Hervé Guétin <[email protected]> <@herveguetin>
 * @copyright Copyright (c) 2018 Kaliop Digital Commerce (http://digitalcommerce.kaliop.com)
 */

namespace Soon\AdminLogger\Model\ResourceModel\Log;
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
    /**
     * @var \Soon\AdminLogger\Model\LogFactory
     */
    private $logFactory;

    public function __construct(
        \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
        \Magento\Framework\Event\ManagerInterface $eventManager,
        \Soon\AdminLogger\Model\LogFactory $logFactory,
        \Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
        \Soon\AdminLogger\Model\ResourceModel\Log $resource = null
    )
    {
        parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
        $this->logFactory = $logFactory;
    }

    protected function _construct()
    {
        $this->_init('Soon\AdminLogger\Model\Log', 'Soon\AdminLogger\Model\ResourceModel\Log');
    }

    public function populateDb()
    {
        $this->getConnection()->truncateTable($this->getMainTable());

        $data = $this->prepareDataForDb();

        while ($dataPacket = $this->arrayChop($data, 10000)) {
            $this->getConnection()->insertMultiple($this->getMainTable(), $dataPacket);
        }
    }

    /**
     * @return array
     * @throws \Magento\Framework\Exception\FileSystemException
     */
    private function prepareDataForDb()
    {
        /** @var \Soon\AdminLogger\Model\Log $log */
        $log = $this->logFactory->create();
        $dbData = array_map(function ($logLine) {
            return [
                'uri'              => $logLine[0],
                'full_action_name' => $logLine[1],
                'is_post'          => (int)$logLine[2],
                'post_data'        => $logLine[3],
                'created_at'       => $logLine[4],
                'admin_user'       => $logLine[5],
            ];
        }, $log->getLoggedData());

        return $dbData;
    }

    /**
     * Chop $num elements off the front of given array
     * Return the chop, shortening subject array
     *
     * @param $arr
     * @param $num
     * @return array
     */
    private function arrayChop(&$arr, $num)
    {
        $ret = array_slice($arr, 0, $num);
        $arr = array_slice($arr, $num);

        return $ret;
    }
}

Spamworldpro Mini