ソースを参照

Use Shim plugin as basis.

Mark Scherer 11 年 前
コミット
cd0312d6db
3 ファイル変更4 行追加326 行削除
  1. 0 47
      Controller/Component/CommonComponent.php
  2. 2 56
      Controller/MyController.php
  3. 2 223
      Model/MyModel.php

+ 0 - 47
Controller/Component/CommonComponent.php

@@ -56,13 +56,6 @@ class CommonComponent extends Component {
 			$this->Controller->request->params['pass'] = $this->trimDeep($this->Controller->request->params['pass']);
 		}
 
-		// Deprecation notices
-		if (Configure::read('App.warnAboutNamedParams')) {
-			if (!empty($Controller->request->params['named']) && ($referer = $Controller->request->referer(true)) && $referer !== '/') {
-				trigger_error('Named params ' . json_encode($Controller->request->params['named']) . ' - from ' . $referer, E_USER_DEPRECATED);
-			}
-		}
-
 		// Information gathering
 		if (!Configure::read('App.disableMobileDetection') && ($mobile = $this->Session->read('Session.mobile')) === null) {
 			App::uses('UserAgentLib', 'Tools.Lib');
@@ -693,26 +686,6 @@ class CommonComponent extends Component {
 	}
 
 	/**
-	 * Main controller function for seo-slugs
-	 * passed titleSlug != current title => redirect to the expected one
-	 *
-	 * @deprecated Will be removed in 1.0
-	 * @return void
-	 */
-	public function ensureConsistency($id, $passedTitleSlug, $currentTitle) {
-		$expectedTitle = slug($currentTitle);
-		if (empty($passedTitleSlug) || $expectedTitle != $passedTitleSlug) { # case sensitive!!!
-			$ref = env('HTTP_REFERER');
-			if (!$this->isForeignReferer($ref)) {
-				$this->Controller->log('Internal ConsistencyProblem at \'' . $ref . '\' - [' . $passedTitleSlug . '] instead of [' . $expectedTitle . ']', 'referer');
-			} else {
-				$this->Controller->log('External ConsistencyProblem at \'' . $ref . '\' - [' . $passedTitleSlug . '] instead of [' . $expectedTitle . ']', 'referer');
-			}
-			$this->Controller->redirect([$id, $expectedTitle], 301);
-		}
-	}
-
-	/**
 	 * Try to detect group for a multidim array for select boxes.
 	 * Extracts the group name of the selected key.
 	 *
@@ -952,26 +925,6 @@ class CommonComponent extends Component {
 	}
 
 	/**
-	 * Returns auto-generated password
-	 *
-	 * @param string $type: user, ...
-	 * @param int $length (if no type is submitted)
-	 * @return pwd on success, empty string otherwise
-	 * @deprecated Will be removed in 1.0. Use RandomLib
-	 */
-	public static function pwd($type = null, $length = null) {
-		trigger_error('deprecated');
-		App::uses('RandomLib', 'Tools.Lib');
-		if (!empty($type) && $type === 'user') {
-			return RandomLib::pronounceablePwd(6);
-		}
-		if (!empty($length)) {
-			return RandomLib::pronounceablePwd($length);
-		}
-		return '';
-	}
-
-	/**
 	 * TODO: move to Lib
 	 * Checks if string contains @ sign
 	 *

+ 2 - 56
Controller/MyController.php

@@ -1,16 +1,10 @@
 <?php
-App::uses('Controller', 'Controller');
+App::uses('ShimController', 'Shim.Controller');
 
 /**
  * DRY Controller stuff
  */
-class MyController extends Controller {
-
-	/**
-	 * @var array
-	 * @link https://github.com/cakephp/cakephp/pull/857
-	 */
-	public $paginate = [];
+class MyController extends ShimController {
 
 	/**
 	 * Fix for asset compress to not run into fatal error loops
@@ -22,52 +16,4 @@ class MyController extends Controller {
 		}
 	}
 
-	/**
-	 * Add headers for IE8 etc to fix caching issues in those stupid browsers
-	 *
-	 * @overwrite to fix IE cacheing issues
-	 * @return void
-	 */
-	public function disableCache() {
-		$this->response->header([
-			'Pragma' => 'no-cache',
-		]);
-		return parent::disableCache();
-	}
-
-	/**
-	 * Handles automatic pagination of model records.
-	 *
-	 * @overwrite to support defaults like limit, querystring settings
-	 * @param Model|string $object Model to paginate (e.g: model instance, or 'Model', or 'Model.InnerModel')
-	 * @param string|array $scope Conditions to use while paginating
-	 * @param array $whitelist List of allowed options for paging
-	 * @return array Model query results
-	 */
-	public function paginate($object = null, $scope = [], $whitelist = []) {
-		if ($defaultSettings = (array)Configure::read('Paginator')) {
-			$this->paginate += $defaultSettings;
-		}
-		return parent::paginate($object, $scope, $whitelist);
-	}
-
-	/**
-	 * Hook to monitor headers being sent.
-	 *
-	 * @return void
-	 */
-	public function afterFilter() {
-		parent::afterFilter();
-
-		if (Configure::read('App.monitorHeaders') && $this->name !== 'CakeError') {
-			if (headers_sent($filename, $linenum)) {
-				$message = sprintf('Headers already sent in %s on line %s', $filename, $linenum);
-				if (Configure::read('debug')) {
-					throw new CakeException($message);
-				}
-				trigger_error($message);
-			}
-		}
-	}
-
 }

+ 2 - 223
Model/MyModel.php

@@ -1,5 +1,5 @@
 <?php
-App::uses('Model', 'Model');
+App::uses('ShimModel', 'Shim.Model');
 App::uses('Utility', 'Tools.Utility');
 App::uses('Hash', 'Utility');
 
@@ -9,11 +9,7 @@ App::uses('Hash', 'Utility');
  * @author Mark Scherer
  * @license http://opensource.org/licenses/mit-license.php MIT
  */
-class MyModel extends Model {
-
-	public $recursive = -1;
-
-	public $actsAs = ['Containable'];
+class MyModel extends ShimModel {
 
 	/**
 	 * MyModel::__construct()
@@ -38,9 +34,6 @@ class MyModel extends Model {
 				'duration'	=> '+1 day'
 			]);
 		}
-		if (!Configure::read('Model.disablePrefixing')) {
-			$this->prefixOrderProperty();
-		}
 
 		// Get a notice if there is an AppModel instance instead of a real Model (in those cases usually a dev error!)
 		if (!is_a($this, $this->name) && $this->displayField !== $this->primaryKey && $this->useDbConfig === 'default'
@@ -50,141 +43,6 @@ class MyModel extends Model {
 	}
 
 	/**
-	 * Prefixes the order property with the actual alias if its a string or array.
-	 *
-	 * The core fails on using the proper prefix when building the query with two
-	 * different tables.
-	 *
-	 * @return void
-	 */
-	public function prefixOrderProperty() {
-		if (is_string($this->order)) {
-			$this->order = $this->prefixAlias($this->order);
-		}
-		if (is_array($this->order)) {
-			foreach ($this->order as $key => $value) {
-				if (is_numeric($key)) {
-					$this->order[$key] = $this->prefixAlias($value);
-				} else {
-					$newKey = $this->prefixAlias($key);
-					$this->order[$newKey] = $value;
-					if ($newKey !== $key) {
-						unset($this->order[$key]);
-					}
-				}
-			}
-		}
-	}
-
-	/**
-	 * Checks if a string of a field name contains a dot if not it will add it and add the alias prefix.
-	 *
-	 * @param string
-	 * @return string
-	 */
-	public function prefixAlias($string) {
-		if (strpos($string, '.') === false) {
-			return $this->alias . '.' . $string;
-		}
-		return $string;
-	}
-
-	/**
-	 * Deconstructs a complex data type (array or object) into a single field value.
-	 * BUGFIXED VERSION - autodetects type and allows manual override
-	 *
-	 * @param string $field The name of the field to be deconstructed
-	 * @param array|object $data An array or object to be deconstructed into a field
-	 * @return mixed The resulting data that should be assigned to a field
-	 */
-	public function deconstruct($field, $data, $type = null) {
-		if (!is_array($data)) {
-			return $data;
-		}
-		if ($type === null) {
-			$type = $this->getColumnType($field);
-		}
-		if ($type === null) {
-			//try to autodetect
-			if (isset($data['day']) || isset($data['month']) || isset($data['year'])) {
-				$type = 'date';
-			}
-			if (isset($data['hour']) || isset($data['min']) || isset($data['sec'])) {
-				$type .= 'time';
-			}
-		}
-
-		if (in_array($type, ['datetime', 'timestamp', 'date', 'time'])) {
-			$useNewDate = (isset($data['year']) || isset($data['month']) ||
-				isset($data['day']) || isset($data['hour']) || isset($data['minute']));
-
-			$dateFields = ['Y' => 'year', 'm' => 'month', 'd' => 'day', 'H' => 'hour', 'i' => 'min', 's' => 'sec'];
-			$timeFields = ['H' => 'hour', 'i' => 'min', 's' => 'sec'];
-			$date = [];
-
-			if (isset($data['meridian']) && empty($data['meridian'])) {
-				return null;
-			}
-
-			if (
-				isset($data['hour']) &&
-				isset($data['meridian']) &&
-				!empty($data['hour']) &&
-				$data['hour'] != 12 &&
-				'pm' == $data['meridian']
-			) {
-				$data['hour'] = $data['hour'] + 12;
-			}
-			if (isset($data['hour']) && isset($data['meridian']) && $data['hour'] == 12 && 'am' == $data['meridian']) {
-				$data['hour'] = '00';
-			}
-			if ($type === 'time') {
-				foreach ($timeFields as $key => $val) {
-					if (!isset($data[$val]) || $data[$val] === '0' || $data[$val] === '00') {
-						$data[$val] = '00';
-					} elseif ($data[$val] !== '') {
-						$data[$val] = sprintf('%02d', $data[$val]);
-					}
-					if (!empty($data[$val])) {
-						$date[$key] = $data[$val];
-					} else {
-						return null;
-					}
-				}
-			}
-
-			if ($type === 'datetime' || $type === 'timestamp' || $type === 'date') {
-				foreach ($dateFields as $key => $val) {
-					if ($val === 'hour' || $val === 'min' || $val === 'sec') {
-						if (!isset($data[$val]) || $data[$val] === '0' || $data[$val] === '00') {
-							$data[$val] = '00';
-						} else {
-							$data[$val] = sprintf('%02d', $data[$val]);
-						}
-					}
-					if (!isset($data[$val]) || isset($data[$val]) && (empty($data[$val]) || $data[$val][0] === '-')) {
-						return null;
-					}
-					if (isset($data[$val]) && !empty($data[$val])) {
-						$date[$key] = $data[$val];
-					}
-				}
-			}
-
-			if ($useNewDate && !empty($date)) {
-				$format = $this->getDataSource()->columns[$type]['format'];
-				foreach (['m', 'd', 'H', 'i', 's'] as $index) {
-					if (isset($date[$index])) {
-						$date[$index] = sprintf('%02d', $date[$index]);
-					}
-				}
-				return str_replace(array_keys($date), array_values($date), $format);
-			}
-		}
-		return $data;
-	}
-
-	/**
 	 * The main method for any enumeration, should be called statically
 	 * Now also supports reordering/filtering
 	 *
@@ -380,54 +238,6 @@ class MyModel extends Model {
 	}
 
 	/**
-	 * Override default updateAll to workaround forced joins.
-	 *
-	 * This is a shim method to more easily migrate to 3.x as there
-	 * updateAll() does not allow joining anymore.
-	 *
-	 * @param array $fields Set of fields and values, indexed by fields.
-	 *   Fields are treated as SQL snippets, to insert literal values manually escape your data.
-	 * @param mixed $conditions Conditions to match, true for all records
-	 * @return bool True on success, false on failure
-	 */
-	public function updateAllJoinless($fields, $conditions = true) {
-		$name = $this->name;
-		$this->name = '_model_';
-
-		try {
-			$result = $this->updateAll($fields, $conditions);
-		} catch (Exception $e) {
-			$this->name = $name;
-			throw $e;
-		}
-
-		$this->name = $name;
-		return $result;
-	}
-
-	/**
-	 * Override default deleteAll to workaround forced joins
-	 *
-	 * This is a shim method to more easily migrate to 3.x as there
-	 * deleteAll() does not allow joining anymore.
-	 *
-	 * @param mixed $conditions Conditions to match
-	 * @param bool $cascade Set to true to delete records that depend on this record
-	 * @param bool $callbacks Run callbacks
-	 * @return bool True on success, false on failure
-	 */
-	public function deleteAllJoinless($conditions, $dependent = true, $callbacks = false) {
-		$associated = [];
-		foreach ($this->getAssociated() as $model => $type) {
-			$associated[$type][] = $model;
-		}
-
-		$this->unbindModel($associated);
-
-		return $this->deleteAll($conditions, $dependent, $callbacks);
-	}
-
-	/**
 	 * Enables HABTM-Validation
 	 * e.g. with
 	 * 'rule' => array('multiple', array('min' => 2))
@@ -784,37 +594,6 @@ class MyModel extends Model {
 	}
 
 	/**
-	 * Delete all records using an atomic query similar to updateAll().
-	 * Note: Does not need manual sanitizing/escaping, though.
-	 *
-	 * Does not do any callbacks
-	 *
-	 * @param mixed $conditions Conditions to match, true for all records
-	 * @return bool Success
-	 */
-	public function deleteAllRaw($conditions = true) {
-		return $this->getDataSource()->delete($this, $conditions);
-	}
-
-	/**
-	 * Overwrite invalidate to allow last => true
-	 *
-	 * @param string $field The name of the field to invalidate
-	 * @param mixed $value Name of validation rule that was not failed, or validation message to
-	 *    be returned. If no validation key is provided, defaults to true.
-	 * @param bool $last If this should be the last validation check for this validation run
-	 * @return void
-	 */
-	public function invalidate($field, $value = true, $last = false) {
-		parent::invalidate($field, $value);
-		if (!$last) {
-			return;
-		}
-
-		$this->validator()->remove($field);
-	}
-
-	/**
 	 * Validates a primary or foreign key depending on the current schema data for this field
 	 * recognizes uuid (char36) and aiid (int10 unsigned) - not yet mixed (varchar36)
 	 * more useful than using numeric or notEmpty which are type specific