Skip to content
This repository
Browse code

Added `$prefix` generation in `core.php` for `cake bake` shell

  • Loading branch information...
commit 8e818c89b69799680ca2a11e5d619ef1641b3b6d 1 parent d66d37c
Tigran Gabrielyan authored January 22, 2012 markstory committed August 24, 2012
27  lib/Cake/Console/Command/Task/ProjectTask.php
@@ -92,6 +92,13 @@ public function execute() {
92 92
 				$success = false;
93 93
 			}
94 94
 
  95
+			if ($this->cachePrefix($path)) {
  96
+				$this->out(__d('cake_console', ' * Cache prefix set'));
  97
+			} else {
  98
+				$this->err(__d('cake_console', 'The cache prefix was <error>NOT</error> set'));
  99
+				$success = false;
  100
+			}
  101
+
95 102
 			if ($this->consolePath($path) === true) {
96 103
 				$this->out(__d('cake_console', ' * app/Console/cake.php path set.'));
97 104
 			} else {
@@ -285,6 +292,26 @@ public function securityCipherSeed($path) {
285 292
 	}
286 293
 
287 294
 /**
  295
+ * Writes cache prefix using app's name
  296
+ *
  297
+ * @param string $dir Path to project
  298
+ * @return boolean Success
  299
+ */
  300
+	public function cachePrefix($dir) {
  301
+		$app = basename($dir);
  302
+		$File = new File($dir . 'Config' . DS . 'core.php');
  303
+		$contents = $File->read();
  304
+		if (preg_match('/(\$prefix = \'myapp_\';)/', $contents, $match)) {
  305
+			$result = str_replace($match[0], '$prefix = \'' . $app . '_\';', $contents);
  306
+			if ($File->write($result)) {
  307
+				return true;
  308
+			}
  309
+			return false;
  310
+		}
  311
+		return false;
  312
+	}
  313
+
  314
+/**
288 315
  * Generates and writes CAKE_CORE_INCLUDE_PATH
289 316
  *
290 317
  * @param string $path Project path

0 notes on commit 8e818c8

Please sign in to comment.
Something went wrong with that request. Please try again.