Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Bake shell core cache `$prefix` generation using app's name #439

Closed
wants to merge 3 commits into from

5 participants

@tigrang

Follow up to #438 in case its wanted.

@lorenzo
Owner

A test case would be ideal! What do you say?

@tigrang

Let there be test!

Sorry didn't realize there were test for these :)

Edit: Simplifying the test. Will amend shortly.

@markstory
Owner

Test all the things!

@tigrang

@markstory did I break something else, or do you mean don't simplify (where some cases are missed).

@josegonzalez
Collaborator

I think he meant run AllTests

@ceeram ceeram commented on the diff
lib/Cake/Console/Command/Task/ProjectTask.php
@@ -300,6 +307,26 @@ public function securityCipherSeed($path) {
}
/**
+ * Writes cache prefix using app's name
+ *
+ * @param string $dir Path to project
+ * @return boolean Success
+ */
+ public function cachePrefix($dir) {
@ceeram Collaborator
ceeram added a note

This will not help when installing multiple complete cakephp installs on shared server, which all use app as dirname.
Edit: sorry, didnt see this was for baked projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@markstory
Owner

Unfunny joke is not funny. I was trying to comment on us having tests for things some projects wouldn't.

@tigrang

sorry for being slower than php @markstory :)

@markstory
Owner

Anyone against putting this into 2.3? I'll manually merge the changes in.

@markstory markstory was assigned
@ceeram
Collaborator

+1
Edit: +1 on merging, not being against it :)

@tigrang tigrang commented on the diff
lib/Cake/Console/Command/Task/ProjectTask.php
@@ -300,6 +307,26 @@ public function securityCipherSeed($path) {
}
/**
+ * Writes cache prefix using app's name
+ *
+ * @param string $dir Path to project
+ * @return boolean Success
+ */
+ public function cachePrefix($dir) {
+ $app = basename($dir);
+ $File = new File($dir . 'Config' . DS . 'core.php');
+ $contents = $File->read();
+ if (preg_match('/(\$prefix = \'myapp_\';)/', $contents, $match)) {
+ $result = str_replace($match[0], '$prefix = \'' . $app . '_\';', $contents);
+ if ($File->write($result)) {
@tigrang
tigrang added a note

This should be changed to just return $File->write($result); This was a copy-paste from another method, so it could be fixed in other places, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@markstory
Owner

Rebased and merged in [0441c9f]

@markstory markstory closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
27 lib/Cake/Console/Command/Task/ProjectTask.php
@@ -92,6 +92,13 @@ public function execute() {
$success = false;
}
+ if ($this->cachePrefix($path)) {
+ $this->out(__d('cake_console', ' * Cache prefix set'));
+ } else {
+ $this->err(__d('cake_console', 'The cache prefix was <error>NOT</error> set'));
+ $success = false;
+ }
+
if ($this->consolePath($path) === true) {
$this->out(__d('cake_console', ' * app/Console/cake.php path set.'));
} else {
@@ -300,6 +307,26 @@ public function securityCipherSeed($path) {
}
/**
+ * Writes cache prefix using app's name
+ *
+ * @param string $dir Path to project
+ * @return boolean Success
+ */
+ public function cachePrefix($dir) {
@ceeram Collaborator
ceeram added a note

This will not help when installing multiple complete cakephp installs on shared server, which all use app as dirname.
Edit: sorry, didnt see this was for baked projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $app = basename($dir);
+ $File = new File($dir . 'Config' . DS . 'core.php');
+ $contents = $File->read();
+ if (preg_match('/(\$prefix = \'myapp_\';)/', $contents, $match)) {
+ $result = str_replace($match[0], '$prefix = \'' . $app . '_\';', $contents);
+ if ($File->write($result)) {
@tigrang
tigrang added a note

This should be changed to just return $File->write($result); This was a copy-paste from another method, so it could be fixed in other places, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return true;
+ }
+ return false;
+ }
+ return false;
+ }
+
+/**
* Generates and writes CAKE_CORE_INCLUDE_PATH
*
* @param string $path Project path
View
18 lib/Cake/Test/Case/Console/Command/Task/ProjectTaskTest.php
@@ -220,6 +220,24 @@ public function testSecurityCipherSeedGeneration() {
}
/**
+ * test generation of cache prefix
+ *
+ * @return void
+ */
+ public function testCachePrefixGeneration() {
+ $this->_setupTestProject();
+
+ $path = $this->Task->path . 'bake_test_app' . DS;
+ $result = $this->Task->cachePrefix($path);
+ $this->assertTrue($result);
+
+ $File = new File($path . 'Config' . DS . 'core.php');
+ $contents = $File->read();
+ $this->assertRegExp('/\$prefix = \'.+\';/', $contents, '$prefix is not defined');
+ $this->assertNotRegExp('/\$prefix = \'myapp_\';/', $contents, 'Default cache prefix left behind. %s');
+ }
+
+/**
* Test that index.php is generated correctly.
*
* @return void
Something went wrong with that request. Please try again.