mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-06 04:28:41 +00:00
fix tests
This commit is contained in:
parent
6e0aebb074
commit
cf72e2f5ec
|
|
@ -583,7 +583,7 @@ final class FileCache extends ConnectionAbstract
|
||||||
$cacheExpire = \substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
|
$cacheExpire = \substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
|
||||||
$cacheExpire = ($cacheExpire === -1) ? $created : (int) $cacheExpire;
|
$cacheExpire = ($cacheExpire === -1) ? $created : (int) $cacheExpire;
|
||||||
|
|
||||||
if ($cacheExpire >= 0 && $created + $cacheExpire + ($expire > 0 ? $expire : 0) < $now) {
|
if ($cacheExpire >= 0 && $created + $cacheExpire + \max(0, $expire) < $now) {
|
||||||
File::delete($path);
|
File::delete($path);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -545,12 +545,12 @@ class Smtp
|
||||||
|
|
||||||
if ($n === 0) {
|
if ($n === 0) {
|
||||||
$name = $type;
|
$name = $type;
|
||||||
$fields = $fields[0];
|
$fields = ($fields === false ? 0 : $fields[0]);
|
||||||
} else {
|
} else {
|
||||||
$name = \array_shift($fields);
|
$name = \array_shift($fields);
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
case 'SIZE':
|
case 'SIZE':
|
||||||
$fields = ($fields ? $fields[0] : 0);
|
$fields = ($fields === false ? 0 : $fields[0]);
|
||||||
break;
|
break;
|
||||||
case 'AUTH':
|
case 'AUTH':
|
||||||
if (!\is_array($fields)) {
|
if (!\is_array($fields)) {
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,6 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
||||||
*/
|
*/
|
||||||
private string $path = '';
|
private string $path = '';
|
||||||
|
|
||||||
private const ALPHABET = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
|
@ -61,37 +59,6 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Turn ints into spreadsheet column names
|
|
||||||
*
|
|
||||||
* @param int $num Column number
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private static function intToString(int $num) : string
|
|
||||||
{
|
|
||||||
if ($num < 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = '';
|
|
||||||
|
|
||||||
while ($num >= 0) {
|
|
||||||
$remainder = $num % 26;
|
|
||||||
$result = self::ALPHABET[$remainder] . $result;
|
|
||||||
|
|
||||||
if ($num < 26) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$num = (int) \floor($num / 26);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -119,7 +86,7 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
||||||
|
|
||||||
// get column titles
|
// get column titles
|
||||||
$column = 1;
|
$column = 1;
|
||||||
while (!empty($value = $workSheet->getCell(self::intToString($column) . 1)->getCalculatedValue())) {
|
while (!empty($value = $workSheet->getCell(StringUtils::intToAlphabet($column) . 1)->getCalculatedValue())) {
|
||||||
$titles[] = $value;
|
$titles[] = $value;
|
||||||
++$column;
|
++$column;
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +150,7 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
||||||
|
|
||||||
// set column titles
|
// set column titles
|
||||||
for ($i = 1; $i <= $colCount; ++$i) {
|
for ($i = 1; $i <= $colCount; ++$i) {
|
||||||
$workSheet->setCellValue(self::intToString($i) . 1, $columns[$i - 1]);
|
$workSheet->setCellValue(StringUtils::intToAlphabet($i) . 1, $columns[$i - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set data
|
// set data
|
||||||
|
|
@ -191,7 +158,7 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
$col = 1;
|
$col = 1;
|
||||||
foreach ($result as $value) {
|
foreach ($result as $value) {
|
||||||
$workSheet->setCellValue(self::intToString($col) . $row, $value);
|
$workSheet->setCellValue(StringUtils::intToAlphabet($col) . $row, $value);
|
||||||
++$col;
|
++$col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -235,7 +202,7 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
||||||
|
|
||||||
// get column titles
|
// get column titles
|
||||||
$column = 1;
|
$column = 1;
|
||||||
while (!empty($value = $workSheet->getCell(self::intToString($column) . 1)->getCalculatedValue())) {
|
while (!empty($value = $workSheet->getCell(StringUtils::intToAlphabet($column) . 1)->getCalculatedValue())) {
|
||||||
$titles[] = $value;
|
$titles[] = $value;
|
||||||
++$column;
|
++$column;
|
||||||
}
|
}
|
||||||
|
|
@ -249,7 +216,7 @@ class SpreadsheetDatabaseMapper implements IODatabaseMapper
|
||||||
$query->update($table)->into($table);
|
$query->update($table)->into($table);
|
||||||
|
|
||||||
for ($j = 2; $j <= $columns; ++$j) {
|
for ($j = 2; $j <= $columns; ++$j) {
|
||||||
$query->sets($titles[$j - 1], $workSheet->getCell(self::intToString($j) . $line)->getCalculatedValue());
|
$query->sets($titles[$j - 1], $workSheet->getCell(StringUtils::intToAlphabet($j) . $line)->getCalculatedValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
$query->where($titles[0], '=', $workSheet->getCell('A' . $line)->getCalculatedValue());
|
$query->where($titles[0], '=', $workSheet->getCell('A' . $line)->getCalculatedValue());
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,14 @@ use phpOMS\Contract\SerializableInterface;
|
||||||
*/
|
*/
|
||||||
final class StringUtils
|
final class StringUtils
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Alphabet list
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private const ALPHABET = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
|
@ -418,4 +426,35 @@ final class StringUtils
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turn ints into spreadsheet column names
|
||||||
|
*
|
||||||
|
* @param int $num Column number
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function intToAlphabet(int $num) : string
|
||||||
|
{
|
||||||
|
if ($num < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = '';
|
||||||
|
|
||||||
|
while ($num >= 0) {
|
||||||
|
$remainder = $num % 26;
|
||||||
|
$result = self::ALPHABET[$remainder] . $result;
|
||||||
|
|
||||||
|
if ($num < 26) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$num = (int) \floor($num / 26);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user