Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
Robot | 84ef5ae035 | |
Robot | 939e0a4daf | |
Robot | cb80680ae8 | |
Robot | 9fc93307ce | |
Robot | 92c174a3a4 | |
Robot | 1519c98533 | |
Robot | 1276456225 | |
Robot | aaad64c935 | |
Robot | f106623873 | |
Robot | 9d0efe46ec | |
Robot | 946b108c06 | |
Robot | 4bd4e35989 |
|
@ -23,6 +23,9 @@ This repository contains an index (see below) of all the approved powers within
|
|||
|
||||
# Index of powers
|
||||
|
||||
- **Namespace**: [TrueChristianChurch\Joomla\Utilities](#truechristianchurch-joomla-utilities)
|
||||
|
||||
- **abstract class MimeHelper** | [Details](src/f11dc790-713e-4706-9a85-a318ed3ad56e) | [Code](src/f11dc790-713e-4706-9a85-a318ed3ad56e/code.php) | [Settings](src/f11dc790-713e-4706-9a85-a318ed3ad56e/settings.json) | Super__f11dc790_713e_4706_9a85_a318ed3ad56e__Power
|
||||
- **Namespace**: [VDM\Joomla\Abstraction](#vdm-joomla-abstraction)
|
||||
|
||||
- **abstract class ActiveRegistry** | [Details](src/43134867-5cb8-4280-9be8-309fd2fd135f) | [Code](src/43134867-5cb8-4280-9be8-309fd2fd135f/code.php) | [Settings](src/43134867-5cb8-4280-9be8-309fd2fd135f/settings.json) | Super__43134867_5cb8_4280_9be8_309fd2fd135f__Power
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class MimeHelper (Details)
|
||||
> namespace: **TrueChristianChurch\Joomla\Utilities**
|
||||
```uml
|
||||
@startuml
|
||||
abstract MimeHelper #Orange {
|
||||
+ {static} mimeType(string $file) : string
|
||||
+ {static} getFileExtensions(string $target = null, boolean $sorted = false) : array
|
||||
}
|
||||
|
||||
note right of MimeHelper::mimeType
|
||||
Get the mime type based on file extension
|
||||
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of MimeHelper::getFileExtensions
|
||||
Get the file extensions
|
||||
|
||||
return: array
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,5 @@
|
|||
[EXTERNALCODE=https://git.vdm.dev/joomla/jcb-external/raw/branch/master/src/file-extension-to-mimetype.php]
|
||||
|
||||
[EXTERNALCODE=https://git.vdm.dev/joomla/jcb-external/raw/branch/master/src/get-mime-type.php]
|
||||
|
||||
[EXTERNALCODE=https://git.vdm.dev/joomla/jcb-external/raw/branch/master/src/get-file-extensions.php]
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "f11dc790-713e-4706-9a85-a318ed3ad56e",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "MimeHelper",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Utilities MimeHelper",
|
||||
"type": "abstract class",
|
||||
"use_selection": null,
|
||||
"namespace": "[[[NamespacePrefix]]]\\Joomla\\Utilities.MimeHelper",
|
||||
"description": "Mime Helper\r\n\r\n@since 3.0.11",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -30,10 +30,10 @@ abstract Schema #Orange {
|
|||
# addMissingColumns(string $table, array $columns) : void
|
||||
# checkColumnsDataType(string $table, array $columns) : void
|
||||
# getColumnDefinition(string $table, string $field) : ?string
|
||||
# checkDefault(string $table, string $column) : void
|
||||
# checkDefault(string $table, string $column) : bool
|
||||
# updateColumnsDataType(string $table, array $columns) : void
|
||||
# getTable(string $table) : string
|
||||
isDataTypeChangeSignificant(string $currentType, string $expectedType) : bool
|
||||
# isDataTypeChangeSignificant(string $currentType, string $expectedType) : bool
|
||||
# adjustExistingDefaults(string $table, string $column, ...) : bool
|
||||
# updateColumnDataType(string $updateString, string $table, ...) : bool
|
||||
# getTableKeys() : string
|
||||
|
@ -41,6 +41,7 @@ abstract Schema #Orange {
|
|||
# setUniqueKey(array $column) : void
|
||||
# setKey(array $column) : void
|
||||
# getDefaultValue(string $type, ?string $defaultValue, ...) : string
|
||||
# quote(mixed $value) : mixed
|
||||
}
|
||||
|
||||
note right of Schema::__construct
|
||||
|
@ -117,7 +118,7 @@ note right of Schema::checkDefault
|
|||
Check and Update the default values if needed, including existing data adjustments
|
||||
|
||||
since: 3.2.1
|
||||
return: void
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note left of Schema::updateColumnsDataType
|
||||
|
@ -138,8 +139,8 @@ note left of Schema::isDataTypeChangeSignificant
|
|||
Determines if the change in data type between two definitions is significant.
|
||||
This function checks if there's a significant difference between the current
|
||||
data type and the expected data type that would require updating the database schema.
|
||||
It ignores size and other modifiers for certain data types where MySQL considers
|
||||
these attributes irrelevant for storage.
|
||||
It ignores display width for numeric types where MySQL considers these attributes
|
||||
irrelevant for storage but considers size and other modifiers for types like VARCHAR.
|
||||
|
||||
since: 3.2.1
|
||||
return: bool
|
||||
|
@ -213,6 +214,13 @@ defaults by either leaving them unset or applying the provided default, properly
|
|||
bool $pure = false
|
||||
end note
|
||||
|
||||
note left of Schema::quote
|
||||
Set a value based on data type
|
||||
|
||||
since: 3.2.0
|
||||
return: mixed
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
|
|
|
@ -342,9 +342,16 @@ abstract class Schema implements SchemaInterface
|
|||
'current' => $current->Type,
|
||||
'expected' => $expected['type']
|
||||
];
|
||||
}
|
||||
|
||||
// check if update of default values is needed
|
||||
$this->checkDefault($table, $column);
|
||||
// check if update of default values is needed
|
||||
if ($this->checkDefault($table, $column) && !isset($requireUpdate[$column]))
|
||||
{
|
||||
$requireUpdate[$column] = [
|
||||
'column' => $column,
|
||||
'current' => $current->Type,
|
||||
'expected' => $expected['type']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -402,29 +409,23 @@ abstract class Schema implements SchemaInterface
|
|||
* @param string $table The table to update.
|
||||
* @param string $column The column/field to check.
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected function checkDefault(string $table, string $column): void
|
||||
protected function checkDefault(string $table, string $column): bool
|
||||
{
|
||||
// Retrieve the expected column configuration
|
||||
$expected = $this->table->get($table, $column, 'db');
|
||||
|
||||
// Skip updates if the column is auto_increment
|
||||
if (isset($expected['auto_increment']) && $expected['auto_increment'])
|
||||
if (isset($expected['auto_increment']) && $expected['auto_increment'] === true)
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Retrieve the current column configuration
|
||||
$current = $this->columns[$column];
|
||||
|
||||
// Check if default should be empty and current default is null, skip processing
|
||||
if (strtoupper($expected['default']) === 'EMPTY' && $current->Default === NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine the new default value based on the expected settings
|
||||
$type = $expected['type'] ?? 'TEXT';
|
||||
$db_default = isset($expected['default']) ? $expected['default'] : null;
|
||||
|
@ -434,7 +435,17 @@ abstract class Schema implements SchemaInterface
|
|||
if (is_numeric($newDefault) && $this->adjustExistingDefaults($table, $column, $current->Default, $newDefault))
|
||||
{
|
||||
$this->success[] = "Success: updated the ($column) defaults in $table table.";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (is_string($expected['default']) && strtoupper($expected['default']) === 'EMPTY' &&
|
||||
is_string($current->Default) && strpos($current->Default, 'EMPTY') !== false)
|
||||
{
|
||||
return true; // little fix
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -486,56 +497,52 @@ abstract class Schema implements SchemaInterface
|
|||
*
|
||||
* This function checks if there's a significant difference between the current
|
||||
* data type and the expected data type that would require updating the database schema.
|
||||
* It ignores size and other modifiers for certain data types where MySQL considers
|
||||
* these attributes irrelevant for storage.
|
||||
* It ignores display width for numeric types where MySQL considers these attributes
|
||||
* irrelevant for storage but considers size and other modifiers for types like VARCHAR.
|
||||
*
|
||||
* @param string $currentType The current data type from the database schema.
|
||||
* @param string $expectedType The expected data type to validate against.
|
||||
* @param string $currentType The current data type from the database schema.
|
||||
* @param string $expectedType The expected data type to validate against.
|
||||
*
|
||||
* @return bool Returns true if the data type change is significant, otherwise false.
|
||||
* @return bool Returns true if the data type change is significant, otherwise false.
|
||||
* @since 3.2.1
|
||||
*/
|
||||
function isDataTypeChangeSignificant(string $currentType, string $expectedType): bool
|
||||
protected function isDataTypeChangeSignificant(string $currentType, string $expectedType): bool
|
||||
{
|
||||
// we only do this for Joomla 4+
|
||||
if ($this->currentVersion != 3)
|
||||
// Normalize both input types to lowercase for case-insensitive comparison
|
||||
$currentType = strtolower($currentType);
|
||||
$expectedType = strtolower($expectedType);
|
||||
|
||||
// Regex to extract the base data type and numeric parameters with named groups
|
||||
$typePattern = '/^(?<datatype>\w+)(\((?<params>\d+(,\d+)?)\))?/';
|
||||
|
||||
// Match types and parameters
|
||||
preg_match($typePattern, $currentType, $currentMatches);
|
||||
preg_match($typePattern, $expectedType, $expectedMatches);
|
||||
|
||||
// Compare base types
|
||||
if ($currentMatches['datatype'] !== $expectedMatches['datatype'])
|
||||
{
|
||||
// Normalize both input types to lowercase for case-insensitive comparison
|
||||
$currentType = strtolower($currentType);
|
||||
$expectedType = strtolower($expectedType);
|
||||
|
||||
// Define types where size or other modifiers are irrelevant
|
||||
$sizeIrrelevantTypes = [
|
||||
'int', 'tinyint', 'smallint', 'mediumint', 'bigint', // Standard integer types
|
||||
'int unsigned', 'tinyint unsigned', 'smallint unsigned', 'mediumint unsigned', 'bigint unsigned', // Unsigned integer types
|
||||
];
|
||||
|
||||
// Check if the type involves size-irrelevant types
|
||||
foreach ($sizeIrrelevantTypes as $type)
|
||||
{
|
||||
if (strpos($expectedType, $type) !== false)
|
||||
{
|
||||
// Remove any numeric sizes and modifiers for comparison
|
||||
$pattern = '/\(\d+\)|unsigned|\s*/';
|
||||
$cleanCurrentType = preg_replace($pattern, '', $currentType);
|
||||
$cleanExpectedType = preg_replace($pattern, '', $expectedType);
|
||||
|
||||
// Compare the cleaned types
|
||||
if ($cleanCurrentType === $cleanExpectedType)
|
||||
{
|
||||
return false; // No significant change
|
||||
}
|
||||
}
|
||||
}
|
||||
return true; // Base types differ
|
||||
}
|
||||
|
||||
// Perform a standard case-insensitive comparison for other types
|
||||
if (strcasecmp($currentType, $expectedType) == 0)
|
||||
// Define types where size and other modifiers are irrelevant
|
||||
$sizeIrrelevantTypes = [
|
||||
'int', 'tinyint', 'smallint', 'mediumint', 'bigint',
|
||||
'float', 'double', 'decimal', 'numeric' // Numeric types where display width is irrelevant
|
||||
];
|
||||
|
||||
// If the type is not in the size irrelevant list, compare full definitions
|
||||
if (!in_array($currentMatches['datatype'], $sizeIrrelevantTypes))
|
||||
{
|
||||
return false; // No significant change
|
||||
return $currentType !== $expectedType; // Use full definition for types where size matters
|
||||
}
|
||||
|
||||
return true; // Significant datatype change detected
|
||||
// For size irrelevant types, only compare base type, ignoring size and unsigned
|
||||
$currentBaseType = preg_replace('/\(\d+(,\d+)?\)|unsigned/', '', $currentType);
|
||||
$expectedBaseType = preg_replace('/\(\d+(,\d+)?\)|unsigned/', '', $expectedType);
|
||||
|
||||
// Perform a final comparison for numeric types ignoring size
|
||||
return $currentBaseType !== $expectedBaseType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -684,7 +691,7 @@ abstract class Schema implements SchemaInterface
|
|||
*/
|
||||
protected function getDefaultValue(string $type, ?string $defaultValue, bool $pure = false): string
|
||||
{
|
||||
if ($defaultValue === null || strtoupper($defaultValue) === 'EMPTY')
|
||||
if ($defaultValue === null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
@ -696,7 +703,52 @@ abstract class Schema implements SchemaInterface
|
|||
}
|
||||
|
||||
// Apply and quote the default value
|
||||
return $pure ? $defaultValue : " DEFAULT " . $this->db->quote($defaultValue);
|
||||
$sql_default = $this->quote($defaultValue);
|
||||
return $pure ? $defaultValue : " DEFAULT $sql_default";
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value based on data type
|
||||
*
|
||||
* @param mixed $value The value to set
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function quote($value)
|
||||
{
|
||||
if ($value === null) // hmm the null does pose an issue (will keep an eye on this)
|
||||
{
|
||||
return 'NULL';
|
||||
}
|
||||
|
||||
if (is_string($value) && strtoupper($value) === 'EMPTY')
|
||||
{
|
||||
return "''";
|
||||
}
|
||||
elseif (is_numeric($value))
|
||||
{
|
||||
if (filter_var($value, FILTER_VALIDATE_INT))
|
||||
{
|
||||
return (int) $value;
|
||||
}
|
||||
elseif (filter_var($value, FILTER_VALIDATE_FLOAT))
|
||||
{
|
||||
return (float) $value;
|
||||
}
|
||||
}
|
||||
elseif (is_bool($value)) // not sure if this will work well (but its correct)
|
||||
{
|
||||
return $value ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
// For date and datetime values
|
||||
elseif ($value instanceof \DateTime)
|
||||
{
|
||||
return $this->db->quote($value->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
// For other data types, just escape it
|
||||
return $this->db->quote($value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -315,9 +315,16 @@
|
|||
'current' => $current->Type,
|
||||
'expected' => $expected['type']
|
||||
];
|
||||
}
|
||||
|
||||
// check if update of default values is needed
|
||||
$this->checkDefault($table, $column);
|
||||
// check if update of default values is needed
|
||||
if ($this->checkDefault($table, $column) && !isset($requireUpdate[$column]))
|
||||
{
|
||||
$requireUpdate[$column] = [
|
||||
'column' => $column,
|
||||
'current' => $current->Type,
|
||||
'expected' => $expected['type']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,29 +382,23 @@
|
|||
* @param string $table The table to update.
|
||||
* @param string $column The column/field to check.
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected function checkDefault(string $table, string $column): void
|
||||
protected function checkDefault(string $table, string $column): bool
|
||||
{
|
||||
// Retrieve the expected column configuration
|
||||
$expected = $this->table->get($table, $column, 'db');
|
||||
|
||||
// Skip updates if the column is auto_increment
|
||||
if (isset($expected['auto_increment']) && $expected['auto_increment'])
|
||||
if (isset($expected['auto_increment']) && $expected['auto_increment'] === true)
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Retrieve the current column configuration
|
||||
$current = $this->columns[$column];
|
||||
|
||||
// Check if default should be empty and current default is null, skip processing
|
||||
if (strtoupper($expected['default']) === 'EMPTY' && $current->Default === NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine the new default value based on the expected settings
|
||||
$type = $expected['type'] ?? 'TEXT';
|
||||
$db_default = isset($expected['default']) ? $expected['default'] : null;
|
||||
|
@ -407,7 +408,17 @@
|
|||
if (is_numeric($newDefault) && $this->adjustExistingDefaults($table, $column, $current->Default, $newDefault))
|
||||
{
|
||||
$this->success[] = "Success: updated the ($column) defaults in $table table.";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (is_string($expected['default']) && strtoupper($expected['default']) === 'EMPTY' &&
|
||||
is_string($current->Default) && strpos($current->Default, 'EMPTY') !== false)
|
||||
{
|
||||
return true; // little fix
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -459,56 +470,52 @@
|
|||
*
|
||||
* This function checks if there's a significant difference between the current
|
||||
* data type and the expected data type that would require updating the database schema.
|
||||
* It ignores size and other modifiers for certain data types where MySQL considers
|
||||
* these attributes irrelevant for storage.
|
||||
* It ignores display width for numeric types where MySQL considers these attributes
|
||||
* irrelevant for storage but considers size and other modifiers for types like VARCHAR.
|
||||
*
|
||||
* @param string $currentType The current data type from the database schema.
|
||||
* @param string $expectedType The expected data type to validate against.
|
||||
* @param string $currentType The current data type from the database schema.
|
||||
* @param string $expectedType The expected data type to validate against.
|
||||
*
|
||||
* @return bool Returns true if the data type change is significant, otherwise false.
|
||||
* @return bool Returns true if the data type change is significant, otherwise false.
|
||||
* @since 3.2.1
|
||||
*/
|
||||
function isDataTypeChangeSignificant(string $currentType, string $expectedType): bool
|
||||
protected function isDataTypeChangeSignificant(string $currentType, string $expectedType): bool
|
||||
{
|
||||
// we only do this for Joomla 4+
|
||||
if ($this->currentVersion != 3)
|
||||
// Normalize both input types to lowercase for case-insensitive comparison
|
||||
$currentType = strtolower($currentType);
|
||||
$expectedType = strtolower($expectedType);
|
||||
|
||||
// Regex to extract the base data type and numeric parameters with named groups
|
||||
$typePattern = '/^(?<datatype>\w+)(\((?<params>\d+(,\d+)?)\))?/';
|
||||
|
||||
// Match types and parameters
|
||||
preg_match($typePattern, $currentType, $currentMatches);
|
||||
preg_match($typePattern, $expectedType, $expectedMatches);
|
||||
|
||||
// Compare base types
|
||||
if ($currentMatches['datatype'] !== $expectedMatches['datatype'])
|
||||
{
|
||||
// Normalize both input types to lowercase for case-insensitive comparison
|
||||
$currentType = strtolower($currentType);
|
||||
$expectedType = strtolower($expectedType);
|
||||
|
||||
// Define types where size or other modifiers are irrelevant
|
||||
$sizeIrrelevantTypes = [
|
||||
'int', 'tinyint', 'smallint', 'mediumint', 'bigint', // Standard integer types
|
||||
'int unsigned', 'tinyint unsigned', 'smallint unsigned', 'mediumint unsigned', 'bigint unsigned', // Unsigned integer types
|
||||
];
|
||||
|
||||
// Check if the type involves size-irrelevant types
|
||||
foreach ($sizeIrrelevantTypes as $type)
|
||||
{
|
||||
if (strpos($expectedType, $type) !== false)
|
||||
{
|
||||
// Remove any numeric sizes and modifiers for comparison
|
||||
$pattern = '/\(\d+\)|unsigned|\s*/';
|
||||
$cleanCurrentType = preg_replace($pattern, '', $currentType);
|
||||
$cleanExpectedType = preg_replace($pattern, '', $expectedType);
|
||||
|
||||
// Compare the cleaned types
|
||||
if ($cleanCurrentType === $cleanExpectedType)
|
||||
{
|
||||
return false; // No significant change
|
||||
}
|
||||
}
|
||||
}
|
||||
return true; // Base types differ
|
||||
}
|
||||
|
||||
// Perform a standard case-insensitive comparison for other types
|
||||
if (strcasecmp($currentType, $expectedType) == 0)
|
||||
// Define types where size and other modifiers are irrelevant
|
||||
$sizeIrrelevantTypes = [
|
||||
'int', 'tinyint', 'smallint', 'mediumint', 'bigint',
|
||||
'float', 'double', 'decimal', 'numeric' // Numeric types where display width is irrelevant
|
||||
];
|
||||
|
||||
// If the type is not in the size irrelevant list, compare full definitions
|
||||
if (!in_array($currentMatches['datatype'], $sizeIrrelevantTypes))
|
||||
{
|
||||
return false; // No significant change
|
||||
return $currentType !== $expectedType; // Use full definition for types where size matters
|
||||
}
|
||||
|
||||
return true; // Significant datatype change detected
|
||||
// For size irrelevant types, only compare base type, ignoring size and unsigned
|
||||
$currentBaseType = preg_replace('/\(\d+(,\d+)?\)|unsigned/', '', $currentType);
|
||||
$expectedBaseType = preg_replace('/\(\d+(,\d+)?\)|unsigned/', '', $expectedType);
|
||||
|
||||
// Perform a final comparison for numeric types ignoring size
|
||||
return $currentBaseType !== $expectedBaseType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -657,7 +664,7 @@
|
|||
*/
|
||||
protected function getDefaultValue(string $type, ?string $defaultValue, bool $pure = false): string
|
||||
{
|
||||
if ($defaultValue === null || strtoupper($defaultValue) === 'EMPTY')
|
||||
if ($defaultValue === null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
@ -669,5 +676,50 @@
|
|||
}
|
||||
|
||||
// Apply and quote the default value
|
||||
return $pure ? $defaultValue : " DEFAULT " . $this->db->quote($defaultValue);
|
||||
$sql_default = $this->quote($defaultValue);
|
||||
return $pure ? $defaultValue : " DEFAULT $sql_default";
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value based on data type
|
||||
*
|
||||
* @param mixed $value The value to set
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function quote($value)
|
||||
{
|
||||
if ($value === null) // hmm the null does pose an issue (will keep an eye on this)
|
||||
{
|
||||
return 'NULL';
|
||||
}
|
||||
|
||||
if (is_string($value) && strtoupper($value) === 'EMPTY')
|
||||
{
|
||||
return "''";
|
||||
}
|
||||
elseif (is_numeric($value))
|
||||
{
|
||||
if (filter_var($value, FILTER_VALIDATE_INT))
|
||||
{
|
||||
return (int) $value;
|
||||
}
|
||||
elseif (filter_var($value, FILTER_VALIDATE_FLOAT))
|
||||
{
|
||||
return (float) $value;
|
||||
}
|
||||
}
|
||||
elseif (is_bool($value)) // not sure if this will work well (but its correct)
|
||||
{
|
||||
return $value ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
// For date and datetime values
|
||||
elseif ($value instanceof \DateTime)
|
||||
{
|
||||
return $this->db->quote($value->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
// For other data types, just escape it
|
||||
return $this->db->quote($value);
|
||||
}
|
|
@ -505,6 +505,17 @@
|
|||
"spk": "Super__e0f6ddbe_2a35_4537_942c_faff2ebd04f6__Power",
|
||||
"guid": "e0f6ddbe-2a35-4537-942c-faff2ebd04f6"
|
||||
},
|
||||
"f11dc790-713e-4706-9a85-a318ed3ad56e": {
|
||||
"name": "MimeHelper",
|
||||
"type": "abstract class",
|
||||
"namespace": "TrueChristianChurch\\Joomla\\Utilities",
|
||||
"code": "src\/f11dc790-713e-4706-9a85-a318ed3ad56e\/code.php",
|
||||
"power": "src\/f11dc790-713e-4706-9a85-a318ed3ad56e\/code.power",
|
||||
"settings": "src\/f11dc790-713e-4706-9a85-a318ed3ad56e\/settings.json",
|
||||
"path": "src\/f11dc790-713e-4706-9a85-a318ed3ad56e",
|
||||
"spk": "Super__f11dc790_713e_4706_9a85_a318ed3ad56e__Power",
|
||||
"guid": "f11dc790-713e-4706-9a85-a318ed3ad56e"
|
||||
},
|
||||
"f3c04c28-bce4-422e-be93-7d163e4e342b": {
|
||||
"name": "Schema",
|
||||
"type": "abstract class",
|
||||
|
|
Loading…
Reference in New Issue