浏览代码

Fix mailer and slugged auto init.

mscherer 5 年之前
父节点
当前提交
dd216cee76

+ 8 - 0
config/Migrations/20200430170235_MigrationToolsTokens.php

@@ -12,6 +12,14 @@ class MigrationToolsTokens extends AbstractMigration {
 	 * @return void
 	 */
 	public function change() {
+		if ($this->table('tokens')->exists()) {
+			$this->table('tokens')
+				->renameColumn('key', 'token_key')
+				->update();
+
+			return;
+		}
+
 		$this->table('tokens')
 			->addColumn('user_id', 'integer', [
 				'limit' => null,

+ 3 - 7
src/Mailer/MailerAwareTrait.php

@@ -31,22 +31,18 @@ trait MailerAwareTrait {
 	 * Returns a mailer instance.
 	 *
 	 * @param string $name Mailer's name.
-	 * @param \Cake\Mailer\Email|null $email Email instance.
+	 * @param array|null $config
 	 * @throws \Cake\Mailer\Exception\MissingMailerException if undefined mailer class.
 	 * @return \Cake\Mailer\Mailer
 	 */
-	public function getMailer($name, ?Email $email = null) {
-		if ($email === null) {
-			$email = new Email();
-		}
-
+	public function getMailer($name, $config = null) {
 		$className = App::className($name, 'Mailer', 'Mailer');
 
 		if (empty($className)) {
 			throw new MissingMailerException(compact('name'));
 		}
 
-		return new $className($email);
+		return new $className($config);
 	}
 
 }

+ 5 - 3
src/Model/Behavior/SluggedBehavior.php

@@ -42,7 +42,7 @@ class SluggedBehavior extends Behavior {
 	 *     display - a dummy mode which returns a slug legal for display - removes illegal (not unprintable) characters
 	 *     url - returns a slug appropriate to put in a URL
 	 *     class - a dummy mode which returns a slug appropriate to put in a html class (there are no restrictions)
-	 *     id - retuns a slug appropriate to use in a html id
+	 *     id - returns a slug appropriate to use in a HTML id
 	 *     OR pass it a callable as custom method to be invoked
 	 * - separator: The separator to use
 	 * - length:
@@ -109,7 +109,6 @@ class SluggedBehavior extends Behavior {
 	 */
 	public function __construct(Table $table, array $config = []) {
 		$this->_defaultConfig['notices'] = Configure::read('debug');
-		$this->_defaultConfig['label'] = $table->getDisplayField();
 		foreach ($this->_defaultConfig['replace'] as $key => $value) {
 			$this->_defaultConfig['replace'][$key] = __d('tools', $value);
 		}
@@ -135,6 +134,10 @@ class SluggedBehavior extends Behavior {
 			$this->_config['length'] = $length;
 		}
 
+		if (!$this->_config['label']) {
+			$this->_config['label'] = $this->_table->getDisplayField();
+		}
+
 		$label = $this->_config['label'] = (array)$this->_config['label'];
 
 		if ($this->_table->behaviors()->has('Translate')) {
@@ -142,7 +145,6 @@ class SluggedBehavior extends Behavior {
 		}
 		if ($this->_config['length']) {
 			foreach ($label as $field) {
-				$alias = $this->_table->getAlias();
 				if (strpos($field, '.')) {
 					[$alias, $field] = explode('.', $field);
 					if (!$this->_table->$alias->hasField($field)) {