Skip to content

Commit 1e100f9

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
2 parents 5210e5e + ce62326 commit 1e100f9

File tree

8 files changed

+123
-18
lines changed

8 files changed

+123
-18
lines changed

phpstan-baseline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@
12331233
];
12341234
$ignoreErrors[] = [
12351235
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
1236-
'count' => 16,
1236+
'count' => 13,
12371237
'path' => __DIR__ . '/system/Database/Forge.php',
12381238
];
12391239
$ignoreErrors[] = [

system/CLI/Console.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public function run()
3535
// Create CLIRequest
3636
$appConfig = config(App::class);
3737
Services::createRequest($appConfig, true);
38+
// Load Routes
39+
Services::routes()->loadRoutes();
3840

3941
$runner = Services::commands();
4042
$params = array_merge(CLI::getSegments(), CLI::getOptions());

system/CodeIgniter.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ private function configureKint(): void
334334
* This is "the loop" if you will. The main entry point into the script
335335
* that gets the required class instances, fires off the filters,
336336
* tries to route the response, loads the controller and generally
337-
* makes all of the pieces work together.
337+
* makes all the pieces work together.
338338
*
339339
* @return ResponseInterface|void
340340
*/
@@ -694,6 +694,8 @@ protected function forceSecureAccess($duration = 31_536_000)
694694
* @return false|ResponseInterface
695695
*
696696
* @throws Exception
697+
*
698+
* @deprecated 4.4.2 The parameter $config is deprecated. No longer used.
697699
*/
698700
public function displayCache(Cache $config)
699701
{
@@ -713,7 +715,7 @@ public function displayCache(Cache $config)
713715
/**
714716
* Tells the app that the final output should be cached.
715717
*
716-
* @deprecated 4.4.0 Moved to ResponseCache::setTtl(). to No longer used.
718+
* @deprecated 4.4.0 Moved to ResponseCache::setTtl(). No longer used.
717719
*
718720
* @return void
719721
*/
@@ -789,7 +791,7 @@ public function displayPerformanceMetrics(string $output): string
789791
* match a route against the current URI. If the route is a
790792
* "redirect route", will also handle the redirect.
791793
*
792-
* @param RouteCollectionInterface|null $routes An collection interface to use in place
794+
* @param RouteCollectionInterface|null $routes A collection interface to use in place
793795
* of the config file.
794796
*
795797
* @return string|string[]|null Route filters, that is, the filters specified in the routes file

system/Database/Forge.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ public function processIndexes(string $table): bool
10731073
$sqls = [];
10741074
$fk = $this->foreignKeys;
10751075

1076-
if (empty($this->fields)) {
1076+
if ($this->fields === []) {
10771077
$this->fields = array_flip(array_map(
10781078
static fn ($columnName) => $columnName->name,
10791079
$this->db->getFieldData($this->db->DBPrefix . $table)
@@ -1082,20 +1082,18 @@ public function processIndexes(string $table): bool
10821082

10831083
$fields = $this->fields;
10841084

1085-
if (! empty($this->keys)) {
1085+
if ($this->keys !== []) {
10861086
$sqls = $this->_processIndexes($this->db->DBPrefix . $table, true);
1087+
}
10871088

1088-
$pk = $this->_processPrimaryKeys($table, true);
1089-
1090-
if ($pk !== '') {
1091-
$sqls[] = $pk;
1092-
}
1089+
if ($this->primaryKeys !== []) {
1090+
$sqls[] = $this->_processPrimaryKeys($table, true);
10931091
}
10941092

10951093
$this->foreignKeys = $fk;
10961094
$this->fields = $fields;
10971095

1098-
if (! empty($this->foreignKeys)) {
1096+
if ($this->foreignKeys !== []) {
10991097
$sqls = array_merge($sqls, $this->_processForeignKeys($table, true));
11001098
}
11011099

system/Honeypot/Honeypot.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,16 @@ public function attachHoneypot(ResponseInterface $response)
8989

9090
$prepField = $this->prepareTemplate($this->config->template);
9191

92-
$body = $response->getBody();
93-
$body = str_ireplace('</form>', $prepField . '</form>', $body);
92+
$bodyBefore = $response->getBody();
93+
$bodyAfter = str_ireplace('</form>', $prepField . '</form>', $bodyBefore);
9494

95-
if ($response->getCSP()->enabled()) {
95+
if ($response->getCSP()->enabled() && ($bodyBefore !== $bodyAfter)) {
9696
// Add style tag for the container tag in the head tag.
97-
$style = '<style ' . csp_style_nonce() . '>#' . $this->config->containerId . ' { display:none }</style>';
98-
$body = str_ireplace('</head>', $style . '</head>', $body);
97+
$style = '<style ' . csp_style_nonce() . '>#' . $this->config->containerId . ' { display:none }</style>';
98+
$bodyAfter = str_ireplace('</head>', $style . '</head>', $bodyAfter);
9999
}
100100

101-
$response->setBody($body);
101+
$response->setBody($bodyAfter);
102102
}
103103

104104
/**

tests/system/Database/Live/ForgeTest.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,87 @@ public function testProcessIndexes(): void
16571657
$this->forge->dropTable('user2', true);
16581658
}
16591659

1660+
public function testProcessIndexesWithKeyOnly(): void
1661+
{
1662+
// make sure tables don't exist
1663+
$this->forge->dropTable('actions', true);
1664+
1665+
$this->createActionsTable();
1666+
$this->forge->addKey('name', false, false, 'db_actions_name');
1667+
1668+
// create indexes
1669+
$this->forge->processIndexes('actions');
1670+
1671+
// get a list of all indexes
1672+
$allIndexes = $this->db->getIndexData('actions');
1673+
1674+
// check that db_actions_name key exists
1675+
$indexes = array_filter(
1676+
$allIndexes,
1677+
static fn ($index) => ($index->name === 'db_actions_name')
1678+
&& ($index->fields === [0 => 'name'])
1679+
);
1680+
$this->assertCount(1, $indexes);
1681+
1682+
// drop tables to avoid any future conflicts
1683+
$this->forge->dropTable('actions', true);
1684+
}
1685+
1686+
public function testProcessIndexesWithPrimaryKeyOnly(): void
1687+
{
1688+
// make sure tables don't exist
1689+
$this->forge->dropTable('actions', true);
1690+
1691+
$this->createActionsTable();
1692+
$this->forge->addPrimaryKey('id');
1693+
1694+
// create indexes
1695+
$this->forge->processIndexes('actions');
1696+
1697+
// get a list of all indexes
1698+
$allIndexes = $this->db->getIndexData('actions');
1699+
1700+
// check that the primary key exists
1701+
$indexes = array_filter(
1702+
$allIndexes,
1703+
static fn ($index) => $index->type === 'PRIMARY'
1704+
);
1705+
$this->assertCount(1, $indexes);
1706+
1707+
// drop tables to avoid any future conflicts
1708+
$this->forge->dropTable('actions', true);
1709+
}
1710+
1711+
public function testProcessIndexesWithForeignKeyOnly(): void
1712+
{
1713+
// make sure tables don't exist
1714+
$this->forge->dropTable('actions', true);
1715+
$this->forge->dropTable('user2', true);
1716+
1717+
$this->createUser2TableWithKeys();
1718+
$this->populateUser2Table();
1719+
$this->createActionsTable();
1720+
1721+
// SQLite does not support custom foreign key name
1722+
if ($this->db->DBDriver === 'SQLite3') {
1723+
$this->forge->addForeignKey('userid', 'user', 'id');
1724+
$this->forge->addForeignKey('userid2', 'user2', 'id');
1725+
} else {
1726+
$this->forge->addForeignKey('userid', 'user', 'id', '', '', 'db_actions_userid_foreign');
1727+
$this->forge->addForeignKey('userid2', 'user2', 'id', '', '', 'db_actions_userid2_foreign');
1728+
}
1729+
1730+
// create indexes
1731+
$this->forge->processIndexes('actions');
1732+
1733+
// check that the two foreign keys exist
1734+
$this->assertCount(2, $this->db->getForeignKeyData('actions'));
1735+
1736+
// drop tables to avoid any future conflicts
1737+
$this->forge->dropTable('actions', true);
1738+
$this->forge->dropTable('user2', true);
1739+
}
1740+
16601741
private function createUser2TableWithKeys(): void
16611742
{
16621743
$fields = [

tests/system/Honeypot/HoneypotTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ public function testAttachHoneypotAndContainerWithCSP(): void
100100
$this->assertMatchesRegularExpression($regex, $this->response->getBody());
101101
}
102102

103+
public function testNotAttachHoneypotWithCSP(): void
104+
{
105+
$this->resetServices();
106+
107+
$config = new App();
108+
$config->CSPEnabled = true;
109+
Factories::injectMock('config', 'App', $config);
110+
$this->response = Services::response($config, false);
111+
112+
$this->config = new HoneypotConfig();
113+
$this->honeypot = new Honeypot($this->config);
114+
115+
$this->response->setBody('<head></head><body></body>');
116+
$this->honeypot->attachHoneypot($this->response);
117+
118+
$this->assertSame('<head></head><body></body>', $this->response->getBody());
119+
}
120+
103121
public function testHasntContent(): void
104122
{
105123
unset($_POST[$this->config->name]);

user_guide_src/source/changelogs/v4.4.2.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Deprecations
3434
details.
3535
- **CLI:** The public property ``CLI::$readline_support`` and ``CLI::$wait_msg``
3636
are deprecated. These methods will be protected.
37+
- **CodeIgniter:** The parameter ``$config`` for the ``displayCache()`` method is
38+
deprecated. It was not used.
3739

3840
Bugs Fixed
3941
**********
@@ -42,6 +44,8 @@ Bugs Fixed
4244
Page Not Found.
4345
- **Spark:** Fixed a bug that caused spark to not display exceptions in the
4446
production mode or to display backtrace in json when an exception occurred.
47+
- **Forge:** Fixed a bug where adding a Primary Key to an existing table was
48+
ignored if there were no other Keys added too.
4549

4650
See the repo's
4751
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

0 commit comments

Comments
 (0)