Skip to content

Commit

Permalink
fix FileSys bug, added webp in ENUM_ALLOWED_IMAGETYPES, fix get varia… (
Browse files Browse the repository at this point in the history
#9)

* fix FileSys bug, added webp in ENUM_ALLOWED_IMAGETYPES, fix get variables for template smarty

* fixed symfony command returned type

* added types

* changed version

---------

Co-authored-by: Yury Bushenko <yury.bushenko@dalee.ru>
  • Loading branch information
Nastro and Yury Bushenko authored Oct 23, 2023
1 parent ee93907 commit b2ef252
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/VERSION
/REVISION
.AppleDouble
/vendor
/vendor/*
!/vendor/Smarty/
/auth.json
composer.lock
*.iml
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change log

## [3.0.1] 2023-10-16
- Исправлена ошибка в Filesys/dir
- Исправлены ошибки в Smarty при обращении к несуществующим переменным в шаблоне
- Добавлен формат webp к списку разрешенных форматов изображений
- Исправлена ошибка определения расширения файла при загрузке на сервер
- Исправлены ошибки возвращаемого типа в командах

## [3.0.0] 2023-08-23
- Обновлена версия php до 8.2
- Обновление phpunit/phpunit до 9.0 lock = `9.6.11`
Expand Down
2 changes: 1 addition & 1 deletion lib/Filesys/dir.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class NLDir
while (true) {
$entry = $this->_dirObject->read();

if ($entry[0] != '.') {
if (($entry[0] ?? '') != '.') {
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/StorageType/File/image.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PXStorageTypeImage extends PXStorageTypeFile
// файл присутствует на диске, обновляем данные по файлу
//
if ($fileName !== null) {
if (!in_array(mb_strtolower(mb_substr($fileName, -3)), $allowedImageTypes)) {
if (!in_array(pathinfo(mb_strtolower($fileName), PATHINFO_EXTENSION), $allowedImageTypes)) {
return null;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/common.defines.inc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ define('ENUM_ALLOWED_IMAGETYPES', [
'image/jpeg' => 'jpg',
'image/pjpeg' => 'jpg',
'image/png' => 'png',
'image/x-png' => 'png'
'image/x-png' => 'png',
'image/webp' => 'webp',
]);

// разрешенные расширения для pathname объектов контентного уровня
Expand Down
2 changes: 1 addition & 1 deletion lib/common.version.inc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

define('PP_VERSION', 'v2.4.9');
define('PP_VERSION', 'v3.0.1');
5 changes: 4 additions & 1 deletion src/Command/CompileContainerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PP\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -33,7 +34,7 @@ protected function configure()
*
* @throws \Exception
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$file = CACHE_PATH . DIRECTORY_SEPARATOR . 'container.php';
$containerConfigCache = new ConfigCache($file, false);
Expand All @@ -50,6 +51,8 @@ public function execute(InputInterface $input, OutputInterface $output)
$dumper->dump(['class' => 'MyCachedContainer']),
$container->getResources()
);

return Command::SUCCESS;
}

}
11 changes: 7 additions & 4 deletions src/Command/CronCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PP\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -32,10 +33,10 @@ protected function configure()
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
if (!isset($this->app->modules['cronrun'])) {
return;
return Command::SUCCESS;
}

/** @var \PP\Module\CronRunModule $cronModule */
Expand Down Expand Up @@ -78,8 +79,8 @@ public function execute(InputInterface $input, OutputInterface $output)
'<comment>' . $title . '</comment>',
mb_str_pad($j['rule']->asString, 15),
$description,
mb_str_pad(strftime("%Y-%m-%d %H:%M:%S", $stat['start']), 21),
mb_str_pad(strftime("%Y-%m-%d %H:%M:%S", $stat['end']), 21),
mb_str_pad(strftime("%Y-%m-%d %H:%M:%S", $stat['start'] ?? null), 21),
mb_str_pad(strftime("%Y-%m-%d %H:%M:%S", $stat['end'] ?? null), 21),
];

$output->writeln(implode(' | ', $row));
Expand All @@ -99,5 +100,7 @@ public function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<info>Starting scheduled jobs..</info>');
$cronModule->RunTasks($this->app, time());
}

return Command::SUCCESS;
}
}
5 changes: 4 additions & 1 deletion src/Command/FillMetaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PP\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use PP\Lib\Command\AbstractCommand;
Expand All @@ -25,7 +26,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$limit = 100;

Expand Down Expand Up @@ -82,5 +83,7 @@ public function execute(InputInterface $input, OutputInterface $output)
}
}
}

return Command::SUCCESS;
}
}
7 changes: 4 additions & 3 deletions src/Command/FillUuidCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PP\Command;

use Ramsey\Uuid\Uuid;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -26,13 +27,13 @@ protected function configure()
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$datatype = $input->getArgument('datatype');
if ($datatype !== null) {
if (!isset($this->app->types[$datatype])) {
$output->writeln('<error>Error:</error> Unknown datatype '.$datatype);
return 1;
return Command::FAILURE;
}

$datatype = $this->app->types[$datatype];
Expand All @@ -44,7 +45,7 @@ public function execute(InputInterface $input, OutputInterface $output)
}
}

return 0;
return Command::SUCCESS;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/Command/GetPropertyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PP\Command;

use PP\Lib\Command\AbstractCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
Expand Down Expand Up @@ -38,7 +39,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$key = $input->getArgument('key');
$stderr = null;
Expand All @@ -51,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (empty($key)) {
if ($stderr instanceof OutputInterface) {
$stderr->writeln("Empty key passed");
return 2;
return Command::INVALID;
}
}

Expand All @@ -62,11 +63,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($stderr instanceof OutputInterface) {
$stderr->writeln("Property: ${key} not found");
}
return 1;
return Command::FAILURE;
}

$result = array_shift($result);
$output->write($result['value']);
return 0;
return Command::SUCCESS;
}
}
5 changes: 4 additions & 1 deletion src/Command/Migrate/MigrateCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PP\Command\Migrate;

use PP\Lib\Command\MigrateAbstractCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -25,7 +26,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$fileName = sprintf("%f", microtime(true));
$fileName = str_replace(',', '', $fileName);
Expand All @@ -50,5 +51,7 @@ public function execute(InputInterface $input, OutputInterface $output)

file_put_contents($writePath, $migrationContent);
$output->writeln("<info>Migration created:</info> ${fileName}");

return Command::SUCCESS;
}
}
7 changes: 5 additions & 2 deletions src/Command/Migrate/MigrateListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PP\Command\Migrate;

use PP\Lib\Command\MigrateAbstractCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -25,17 +26,19 @@ protected function configure()
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$migrationList = $this->getPendingMigrations();
if (count($migrationList) === 0) {
$output->writeln("No pending migrations");
return 0;
return Command::SUCCESS;
}

$output->writeln("Pending migrations list:");
foreach ($migrationList as $migration) {
$output->writeln("<info>${migration}</info>");
}

return Command::SUCCESS;
}
}
7 changes: 5 additions & 2 deletions src/Command/Migrate/MigrateUpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PP\Lib\Command\MigrateAbstractCommand;
use PP\Migration\MigrationAbstract;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -26,12 +27,12 @@ protected function configure()
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$migrationList = $this->getPendingMigrations();
if (count($migrationList) === 0) {
$output->writeln("No pending migrations");
return 0;
return Command::SUCCESS;
}

$this->dbDriver->transactionBegin();
Expand Down Expand Up @@ -69,6 +70,8 @@ public function execute(InputInterface $input, OutputInterface $output)
$this->dbDriver->transactionRollback();
throw $e;
}

return Command::SUCCESS;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Command/SetPropertyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PP\Lib\Command\AbstractCommand;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -33,7 +34,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$key = $input->getArgument('key');
$val = $input->getArgument('val');
Expand Down Expand Up @@ -62,5 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->db->InsertObject(DT_PROPERTIES, $dbFields, $dbValues);
$output->writeln("Property: ${key}: <info>inserted</info>");
}

return Command::SUCCESS;
}
}
10 changes: 7 additions & 3 deletions vendor/Smarty/Smarty.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

include_once __DIR__ . '/SmartyTmplVarsBag.php';

/**
* Project: Smarty: the PHP compiling template engine
* File: Smarty.class.php
Expand Down Expand Up @@ -408,7 +410,7 @@ class Smarty
*
* @var array
*/
public $_tpl_vars = [];
public $_tpl_vars = null;

/**
* stores run-time $smarty.* vars
Expand Down Expand Up @@ -567,6 +569,8 @@ class Smarty
*/
public function __construct()
{
$this->_tpl_vars = new SmartyTmplVarsBag();

$this->assign('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME']
: @$GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
}
Expand Down Expand Up @@ -600,7 +604,7 @@ public function assign($tpl_var, $value = null)
public function assign_by_ref($tpl_var, &$value)
{
if ($tpl_var != '')
$this->_tpl_vars[$tpl_var] = &$value;
$this->_tpl_vars[$tpl_var] = $value;
}

/**
Expand Down Expand Up @@ -1860,7 +1864,7 @@ public function _smarty_include($params)
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
}

$this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']);
$this->_tpl_vars->merge($params['smarty_include_vars']);

// config vars are treated as local, so push a copy of the
// current ones onto the front of the stack
Expand Down
Loading

0 comments on commit b2ef252

Please sign in to comment.