mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-02 22:23:38 +02:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
@ -4,20 +4,21 @@
|
|||
*
|
||||
* Enables objects to easily tie into an ACL system
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc.
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package Cake.Model.Behavior
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('ModelBehavior', 'Model');
|
||||
App::uses('AclNode', 'Model');
|
||||
App::uses('Hash', 'Utility');
|
||||
|
||||
|
@ -41,8 +42,8 @@ class AclBehavior extends ModelBehavior {
|
|||
/**
|
||||
* Sets up the configuration for the model, and loads ACL models if they haven't been already
|
||||
*
|
||||
* @param Model $model
|
||||
* @param array $config
|
||||
* @param Model $model Model using this behavior.
|
||||
* @param array $config Configuration options.
|
||||
* @return void
|
||||
*/
|
||||
public function setup(Model $model, $config = array()) {
|
||||
|
@ -62,14 +63,14 @@ class AclBehavior extends ModelBehavior {
|
|||
$model->{$type} = ClassRegistry::init($type);
|
||||
}
|
||||
if (!method_exists($model, 'parentNode')) {
|
||||
trigger_error(__d('cake_dev', 'Callback parentNode() not defined in %s', $model->alias), E_USER_WARNING);
|
||||
trigger_error(__d('cake_dev', 'Callback %s not defined in %s', 'parentNode()', $model->alias), E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the Aro/Aco node for this model
|
||||
*
|
||||
* @param Model $model
|
||||
* @param Model $model Model using this behavior.
|
||||
* @param string|array|Model $ref Array with 'model' and 'foreign_key', model object, or string value
|
||||
* @param string $type Only needed when Acl is set up as 'both', specify 'Aro' or 'Aco' to get the correct node
|
||||
* @return array
|
||||
|
@ -80,7 +81,7 @@ class AclBehavior extends ModelBehavior {
|
|||
$type = $this->_typeMaps[$this->settings[$model->name]['type']];
|
||||
if (is_array($type)) {
|
||||
trigger_error(__d('cake_dev', 'AclBehavior is setup with more then one type, please specify type parameter for node()'), E_USER_WARNING);
|
||||
return null;
|
||||
return array();
|
||||
}
|
||||
}
|
||||
if (empty($ref)) {
|
||||
|
@ -92,17 +93,18 @@ class AclBehavior extends ModelBehavior {
|
|||
/**
|
||||
* Creates a new ARO/ACO node bound to this record
|
||||
*
|
||||
* @param Model $model
|
||||
* @param boolean $created True if this is a new record
|
||||
* @param Model $model Model using this behavior.
|
||||
* @param bool $created True if this is a new record
|
||||
* @param array $options Options passed from Model::save().
|
||||
* @return void
|
||||
*/
|
||||
public function afterSave(Model $model, $created) {
|
||||
public function afterSave(Model $model, $created, $options = array()) {
|
||||
$types = $this->_typeMaps[$this->settings[$model->name]['type']];
|
||||
if (!is_array($types)) {
|
||||
$types = array($types);
|
||||
}
|
||||
foreach ($types as $type) {
|
||||
$parent = $model->parentNode();
|
||||
$parent = $model->parentNode($type);
|
||||
if (!empty($parent)) {
|
||||
$parent = $this->node($model, $parent, $type);
|
||||
}
|
||||
|
@ -123,7 +125,7 @@ class AclBehavior extends ModelBehavior {
|
|||
/**
|
||||
* Destroys the ARO/ACO node bound to the deleted record
|
||||
*
|
||||
* @param Model $model
|
||||
* @param Model $model Model using this behavior.
|
||||
* @return void
|
||||
*/
|
||||
public function afterDelete(Model $model) {
|
||||
|
|
|
@ -4,21 +4,22 @@
|
|||
*
|
||||
* Behavior to simplify manipulating a model's bindings when doing a find operation
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Model.Behavior
|
||||
* @since CakePHP(tm) v 1.2.0.5669
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('ModelBehavior', 'Model');
|
||||
|
||||
/**
|
||||
* Behavior to allow for dynamic and atomic manipulation of a Model's associations
|
||||
* used for a find call. Most useful for limiting the amount of associations and
|
||||
|
@ -74,7 +75,7 @@ class ContainableBehavior extends ModelBehavior {
|
|||
*
|
||||
* `Model->find('all', array('contain' => array('Model1', 'Model2')));`
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* Model->find('all', array('contain' => array(
|
||||
* 'Model1' => array('Model11', 'Model12'),
|
||||
* 'Model2',
|
||||
|
@ -83,9 +84,9 @@ class ContainableBehavior extends ModelBehavior {
|
|||
* 'Model32',
|
||||
* 'Model33' => array('Model331', 'Model332')
|
||||
* )));
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* @param Model $Model Model using the behavior
|
||||
* @param Model $Model Model using the behavior
|
||||
* @param array $query Query parameters as set by cake
|
||||
* @return array
|
||||
*/
|
||||
|
@ -108,9 +109,7 @@ class ContainableBehavior extends ModelBehavior {
|
|||
}
|
||||
$noContain = $noContain && empty($contain);
|
||||
|
||||
if (
|
||||
$noContain || empty($contain) || (isset($contain[0]) && $contain[0] === null)
|
||||
) {
|
||||
if ($noContain || empty($contain)) {
|
||||
if ($noContain) {
|
||||
$query['recursive'] = -1;
|
||||
}
|
||||
|
@ -125,7 +124,7 @@ class ContainableBehavior extends ModelBehavior {
|
|||
$map = $this->containmentsMap($containments);
|
||||
|
||||
$mandatory = array();
|
||||
foreach ($containments['models'] as $name => $model) {
|
||||
foreach ($containments['models'] as $model) {
|
||||
$instance = $model['instance'];
|
||||
$needed = $this->fieldDependencies($instance, $map, false);
|
||||
if (!empty($needed)) {
|
||||
|
@ -174,7 +173,7 @@ class ContainableBehavior extends ModelBehavior {
|
|||
}
|
||||
|
||||
if ($this->settings[$Model->alias]['recursive']) {
|
||||
$query['recursive'] = (isset($query['recursive'])) ? $query['recursive'] : $containments['depth'];
|
||||
$query['recursive'] = (isset($query['recursive'])) ? max($query['recursive'], $containments['depth']) : $containments['depth'];
|
||||
}
|
||||
|
||||
$autoFields = ($this->settings[$Model->alias]['autoFields']
|
||||
|
@ -189,7 +188,7 @@ class ContainableBehavior extends ModelBehavior {
|
|||
foreach (array('hasOne', 'belongsTo') as $type) {
|
||||
if (!empty($Model->{$type})) {
|
||||
foreach ($Model->{$type} as $assoc => $data) {
|
||||
if ($Model->useDbConfig == $Model->{$assoc}->useDbConfig && !empty($data['fields'])) {
|
||||
if ($Model->useDbConfig === $Model->{$assoc}->useDbConfig && !empty($data['fields'])) {
|
||||
foreach ((array)$data['fields'] as $field) {
|
||||
$query['fields'][] = (strpos($field, '.') === false ? $assoc . '.' : '') . $field;
|
||||
}
|
||||
|
@ -200,11 +199,11 @@ class ContainableBehavior extends ModelBehavior {
|
|||
|
||||
if (!empty($mandatory[$Model->alias])) {
|
||||
foreach ($mandatory[$Model->alias] as $field) {
|
||||
if ($field == '--primaryKey--') {
|
||||
if ($field === '--primaryKey--') {
|
||||
$field = $Model->primaryKey;
|
||||
} elseif (preg_match('/^.+\.\-\-[^-]+\-\-$/', $field)) {
|
||||
list($modelName, $field) = explode('.', $field);
|
||||
if ($Model->useDbConfig == $Model->{$modelName}->useDbConfig) {
|
||||
if ($Model->useDbConfig === $Model->{$modelName}->useDbConfig) {
|
||||
$field = $modelName . '.' . (
|
||||
($field === '--primaryKey--') ? $Model->$modelName->primaryKey : $field
|
||||
);
|
||||
|
@ -264,11 +263,11 @@ class ContainableBehavior extends ModelBehavior {
|
|||
* @param Model $Model Model on which binding restriction is being applied
|
||||
* @param array $contain Parameters to use for restricting this model
|
||||
* @param array $containments Current set of containments
|
||||
* @param boolean $throwErrors Whether non-existent bindings show throw errors
|
||||
* @param bool $throwErrors Whether non-existent bindings show throw errors
|
||||
* @return array Containments
|
||||
*/
|
||||
public function containments(Model $Model, $contain, $containments = array(), $throwErrors = null) {
|
||||
$options = array('className', 'joinTable', 'with', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery', 'deleteQuery', 'insertQuery');
|
||||
$options = array('className', 'joinTable', 'with', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery');
|
||||
$keep = array();
|
||||
if ($throwErrors === null) {
|
||||
$throwErrors = (empty($this->settings[$Model->alias]) ? true : $this->settings[$Model->alias]['notices']);
|
||||
|
@ -307,7 +306,7 @@ class ContainableBehavior extends ModelBehavior {
|
|||
if (!$optionKey && is_string($key) && preg_match('/^[a-z(]/', $key) && (!isset($Model->{$key}) || !is_object($Model->{$key}))) {
|
||||
$option = 'fields';
|
||||
$val = array($key);
|
||||
if ($key{0} == '(') {
|
||||
if ($key{0} === '(') {
|
||||
$val = preg_split('/\s*,\s*/', substr($key, 1, -1));
|
||||
} elseif (preg_match('/ASC|DESC$/', $key)) {
|
||||
$option = 'order';
|
||||
|
@ -366,7 +365,7 @@ class ContainableBehavior extends ModelBehavior {
|
|||
*
|
||||
* @param Model $Model Model
|
||||
* @param array $map Map of relations for given model
|
||||
* @param array|boolean $fields If array, fields to initially load, if false use $Model as primary model
|
||||
* @param array|bool $fields If array, fields to initially load, if false use $Model as primary model
|
||||
* @return array Fields
|
||||
*/
|
||||
public function fieldDependencies(Model $Model, $map, $fields = array()) {
|
||||
|
@ -374,9 +373,9 @@ class ContainableBehavior extends ModelBehavior {
|
|||
foreach ($map as $parent => $children) {
|
||||
foreach ($children as $type => $bindings) {
|
||||
foreach ($bindings as $dependency) {
|
||||
if ($type == 'hasAndBelongsToMany') {
|
||||
if ($type === 'hasAndBelongsToMany') {
|
||||
$fields[$parent][] = '--primaryKey--';
|
||||
} elseif ($type == 'belongsTo') {
|
||||
} elseif ($type === 'belongsTo') {
|
||||
$fields[$parent][] = $dependency . '.--primaryKey--';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Model.Behavior
|
||||
* @since CakePHP(tm) v 1.2.0.4525
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('ModelBehavior', 'Model');
|
||||
App::uses('I18n', 'I18n');
|
||||
App::uses('I18nModel', 'Model');
|
||||
|
||||
|
@ -119,7 +121,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
$this->_joinTable = $joinTable;
|
||||
$this->_runtimeModel = $RuntimeModel;
|
||||
|
||||
if (is_string($query['fields']) && "COUNT(*) AS {$db->name('count')}" == $query['fields']) {
|
||||
if (is_string($query['fields']) && $query['fields'] === "COUNT(*) AS {$db->name('count')}") {
|
||||
$query['fields'] = "COUNT(DISTINCT({$db->name($Model->escapeField())})) {$db->alias}count";
|
||||
$query['joins'][] = array(
|
||||
'type' => 'INNER',
|
||||
|
@ -128,7 +130,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
'conditions' => array(
|
||||
$Model->escapeField() => $db->identifier($RuntimeModel->escapeField('foreign_key')),
|
||||
$RuntimeModel->escapeField('model') => $Model->name,
|
||||
$RuntimeModel->escapeField('locale') => $locale
|
||||
$RuntimeModel->escapeField('locale') => $locale
|
||||
)
|
||||
);
|
||||
$conditionFields = $this->_checkConditions($Model, $query);
|
||||
|
@ -137,6 +139,8 @@ class TranslateBehavior extends ModelBehavior {
|
|||
}
|
||||
unset($this->_joinTable, $this->_runtimeModel);
|
||||
return $query;
|
||||
} elseif (is_string($query['fields'])) {
|
||||
$query['fields'] = CakeText::tokenize($query['fields']);
|
||||
}
|
||||
|
||||
$fields = array_merge(
|
||||
|
@ -153,8 +157,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
);
|
||||
foreach ($fields as $key => $value) {
|
||||
$field = (is_numeric($key)) ? $value : $key;
|
||||
if (
|
||||
$isAllFields ||
|
||||
if ($isAllFields ||
|
||||
in_array($Model->alias . '.' . $field, $query['fields']) ||
|
||||
in_array($field, $query['fields'])
|
||||
) {
|
||||
|
@ -193,7 +196,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
*/
|
||||
protected function _checkConditions(Model $Model, $query) {
|
||||
$conditionFields = array();
|
||||
if (empty($query['conditions']) || (!empty($query['conditions']) && !is_array($query['conditions'])) ) {
|
||||
if (empty($query['conditions']) || (!empty($query['conditions']) && !is_array($query['conditions']))) {
|
||||
return $conditionFields;
|
||||
}
|
||||
foreach ($query['conditions'] as $col => $val) {
|
||||
|
@ -213,12 +216,11 @@ class TranslateBehavior extends ModelBehavior {
|
|||
* Appends a join for translated fields.
|
||||
*
|
||||
* @param Model $Model The model being worked on.
|
||||
* @param object $joinTable The jointable object.
|
||||
* @param array $query The query array to append a join to.
|
||||
* @param string $field The field name being joined.
|
||||
* @param string $aliasField The aliased field name being joined.
|
||||
* @param string|array $locale The locale(s) having joins added.
|
||||
* @return array The modfied query
|
||||
* @return array The modified query
|
||||
*/
|
||||
protected function _addJoin(Model $Model, $query, $field, $aliasField, $locale) {
|
||||
$db = ConnectionManager::getDataSource($Model->useDbConfig);
|
||||
|
@ -271,12 +273,18 @@ class TranslateBehavior extends ModelBehavior {
|
|||
*
|
||||
* @param Model $Model Model find was run on
|
||||
* @param array $results Array of model results.
|
||||
* @param boolean $primary Did the find originate on $model.
|
||||
* @param bool $primary Did the find originate on $model.
|
||||
* @return array Modified results
|
||||
*/
|
||||
public function afterFind(Model $Model, $results, $primary) {
|
||||
public function afterFind(Model $Model, $results, $primary = false) {
|
||||
$Model->virtualFields = $this->runtime[$Model->alias]['virtualFields'];
|
||||
|
||||
$this->runtime[$Model->alias]['virtualFields'] = $this->runtime[$Model->alias]['fields'] = array();
|
||||
if (!empty($this->runtime[$Model->alias]['restoreFields'])) {
|
||||
$this->runtime[$Model->alias]['fields'] = $this->runtime[$Model->alias]['restoreFields'];
|
||||
unset($this->runtime[$Model->alias]['restoreFields']);
|
||||
}
|
||||
|
||||
$locale = $this->_getLocale($Model);
|
||||
|
||||
if (empty($locale) || empty($results) || empty($this->runtime[$Model->alias]['beforeFind'])) {
|
||||
|
@ -304,7 +312,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
}
|
||||
} else {
|
||||
$value = '';
|
||||
if (!empty($row[$Model->alias][$aliasVirtual])) {
|
||||
if (isset($row[$Model->alias][$aliasVirtual])) {
|
||||
$value = $row[$Model->alias][$aliasVirtual];
|
||||
}
|
||||
$row[$Model->alias][$aliasField] = $value;
|
||||
|
@ -319,9 +327,11 @@ class TranslateBehavior extends ModelBehavior {
|
|||
* beforeValidate Callback
|
||||
*
|
||||
* @param Model $Model Model invalidFields was called on.
|
||||
* @return boolean
|
||||
* @param array $options Options passed from Model::save().
|
||||
* @return bool
|
||||
* @see Model::save()
|
||||
*/
|
||||
public function beforeValidate(Model $Model) {
|
||||
public function beforeValidate(Model $Model, $options = array()) {
|
||||
unset($this->runtime[$Model->alias]['beforeSave']);
|
||||
$this->_setRuntimeData($Model);
|
||||
return true;
|
||||
|
@ -331,13 +341,15 @@ class TranslateBehavior extends ModelBehavior {
|
|||
* beforeSave callback.
|
||||
*
|
||||
* Copies data into the runtime property when `$options['validate']` is
|
||||
* disabled. Or the runtime data hasn't been set yet.
|
||||
* disabled. Or the runtime data hasn't been set yet.
|
||||
*
|
||||
* @param Model $Model Model save was called on.
|
||||
* @return boolean true.
|
||||
* @param array $options Options passed from Model::save().
|
||||
* @return bool true.
|
||||
* @see Model::save()
|
||||
*/
|
||||
public function beforeSave(Model $Model, $options = array()) {
|
||||
if (isset($options['validate']) && $options['validate'] == false) {
|
||||
if (isset($options['validate']) && !$options['validate']) {
|
||||
unset($this->runtime[$Model->alias]['beforeSave']);
|
||||
}
|
||||
if (isset($this->runtime[$Model->alias]['beforeSave'])) {
|
||||
|
@ -354,7 +366,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
* and to allow translations to be persisted even when validation
|
||||
* is disabled.
|
||||
*
|
||||
* @param Model $Model
|
||||
* @param Model $Model Model using this behavior.
|
||||
* @return void
|
||||
*/
|
||||
protected function _setRuntimeData(Model $Model) {
|
||||
|
@ -387,7 +399,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
* Restores model data to the original data.
|
||||
* This solves issues with saveAssociated and validate = first.
|
||||
*
|
||||
* @param Model $model
|
||||
* @param Model $Model Model using this behavior.
|
||||
* @return void
|
||||
*/
|
||||
public function afterValidate(Model $Model) {
|
||||
|
@ -402,14 +414,14 @@ class TranslateBehavior extends ModelBehavior {
|
|||
* afterSave Callback
|
||||
*
|
||||
* @param Model $Model Model the callback is called on
|
||||
* @param boolean $created Whether or not the save created a record.
|
||||
* @param bool $created Whether or not the save created a record.
|
||||
* @param array $options Options passed from Model::save().
|
||||
* @return void
|
||||
*/
|
||||
public function afterSave(Model $Model, $created) {
|
||||
public function afterSave(Model $Model, $created, $options = array()) {
|
||||
if (!isset($this->runtime[$Model->alias]['beforeValidate']) && !isset($this->runtime[$Model->alias]['beforeSave'])) {
|
||||
return true;
|
||||
}
|
||||
$locale = $this->_getLocale($Model);
|
||||
if (isset($this->runtime[$Model->alias]['beforeValidate'])) {
|
||||
$tempData = $this->runtime[$Model->alias]['beforeValidate'];
|
||||
} else {
|
||||
|
@ -417,23 +429,16 @@ class TranslateBehavior extends ModelBehavior {
|
|||
}
|
||||
|
||||
unset($this->runtime[$Model->alias]['beforeValidate'], $this->runtime[$Model->alias]['beforeSave']);
|
||||
$conditions = array('model' => $Model->alias, 'foreign_key' => $Model->id);
|
||||
$conditions = array('model' => $Model->name, 'foreign_key' => $Model->id);
|
||||
$RuntimeModel = $this->translateModel($Model);
|
||||
|
||||
$fields = array_merge(
|
||||
$this->settings[$Model->alias],
|
||||
$this->runtime[$Model->alias]['fields']
|
||||
);
|
||||
if ($created) {
|
||||
// set each field value to an empty string
|
||||
foreach ($fields as $key => $field) {
|
||||
if (!is_numeric($key)) {
|
||||
$field = $key;
|
||||
}
|
||||
if (!isset($tempData[$field])) {
|
||||
$tempData[$field] = '';
|
||||
}
|
||||
}
|
||||
$tempData = $this->_prepareTranslations($Model, $tempData);
|
||||
}
|
||||
$locale = $this->_getLocale($Model);
|
||||
$atomic = array();
|
||||
if (isset($options['atomic'])) {
|
||||
$atomic = array('atomic' => $options['atomic']);
|
||||
}
|
||||
|
||||
foreach ($tempData as $field => $value) {
|
||||
|
@ -451,7 +456,10 @@ class TranslateBehavior extends ModelBehavior {
|
|||
}
|
||||
$translations = $RuntimeModel->find('list', array(
|
||||
'conditions' => $conditions,
|
||||
'fields' => array($RuntimeModel->alias . '.locale', $RuntimeModel->alias . '.id')
|
||||
'fields' => array(
|
||||
$RuntimeModel->alias . '.locale',
|
||||
$RuntimeModel->alias . '.id'
|
||||
)
|
||||
));
|
||||
foreach ($value as $_locale => $_value) {
|
||||
$RuntimeModel->create();
|
||||
|
@ -461,15 +469,48 @@ class TranslateBehavior extends ModelBehavior {
|
|||
$RuntimeModel->save(array(
|
||||
$RuntimeModel->alias => array_merge(
|
||||
$conditions, array('id' => $translations[$_locale])
|
||||
)
|
||||
),
|
||||
$atomic
|
||||
));
|
||||
} else {
|
||||
$RuntimeModel->save(array($RuntimeModel->alias => $conditions));
|
||||
$RuntimeModel->save(array($RuntimeModel->alias => $conditions), $atomic);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the data to be saved for translated records.
|
||||
* Add blank fields, and populates data for multi-locale saves.
|
||||
*
|
||||
* @param Model $Model Model using this behavior
|
||||
* @param array $data The sparse data that was provided.
|
||||
* @return array The fully populated data to save.
|
||||
*/
|
||||
protected function _prepareTranslations(Model $Model, $data) {
|
||||
$fields = array_merge($this->settings[$Model->alias], $this->runtime[$Model->alias]['fields']);
|
||||
$locales = array();
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$locales = array_merge($locales, array_keys($value));
|
||||
}
|
||||
}
|
||||
$locales = array_unique($locales);
|
||||
$hasLocales = count($locales) > 0;
|
||||
|
||||
foreach ($fields as $key => $field) {
|
||||
if (!is_numeric($key)) {
|
||||
$field = $key;
|
||||
}
|
||||
if ($hasLocales && !isset($data[$field])) {
|
||||
$data[$field] = array_fill_keys($locales, '');
|
||||
} elseif (!isset($data[$field])) {
|
||||
$data[$field] = '';
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* afterDelete Callback
|
||||
*
|
||||
|
@ -478,10 +519,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
*/
|
||||
public function afterDelete(Model $Model) {
|
||||
$RuntimeModel = $this->translateModel($Model);
|
||||
$conditions = array(
|
||||
'model' => $Model->alias,
|
||||
'foreign_key' => $Model->id
|
||||
);
|
||||
$conditions = array('model' => $Model->name, 'foreign_key' => $Model->id);
|
||||
$RuntimeModel->deleteAll($conditions);
|
||||
}
|
||||
|
||||
|
@ -492,7 +530,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
* @return mixed string or false
|
||||
*/
|
||||
protected function _getLocale(Model $Model) {
|
||||
if (!isset($Model->locale) || is_null($Model->locale)) {
|
||||
if (!isset($Model->locale) || $Model->locale === null) {
|
||||
$I18n = I18n::getInstance();
|
||||
$I18n->l10n->get(Configure::read('Config.language'));
|
||||
$Model->locale = $I18n->l10n->locale;
|
||||
|
@ -505,7 +543,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
* Get instance of model for translations.
|
||||
*
|
||||
* If the model has a translateModel property set, this will be used as the class
|
||||
* name to find/use. If no translateModel property is found 'I18nModel' will be used.
|
||||
* name to find/use. If no translateModel property is found 'I18nModel' will be used.
|
||||
*
|
||||
* @param Model $Model Model to get a translatemodel for.
|
||||
* @return Model
|
||||
|
@ -518,7 +556,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
$className = $Model->translateModel;
|
||||
}
|
||||
|
||||
$this->runtime[$Model->alias]['model'] = ClassRegistry::init($className, 'Model');
|
||||
$this->runtime[$Model->alias]['model'] = ClassRegistry::init($className);
|
||||
}
|
||||
if (!empty($Model->translateTable) && $Model->translateTable !== $this->runtime[$Model->alias]['model']->useTable) {
|
||||
$this->runtime[$Model->alias]['model']->setSource($Model->translateTable);
|
||||
|
@ -535,12 +573,12 @@ class TranslateBehavior extends ModelBehavior {
|
|||
* *Note* You should avoid binding translations that overlap existing model properties.
|
||||
* This can cause un-expected and un-desirable behavior.
|
||||
*
|
||||
* @param Model $Model instance of model
|
||||
* @param Model $Model using this behavior of model
|
||||
* @param string|array $fields string with field or array(field1, field2=>AssocName, field3)
|
||||
* @param boolean $reset Leave true to have the fields only modified for the next operation.
|
||||
* @param bool $reset Leave true to have the fields only modified for the next operation.
|
||||
* if false the field will be added for all future queries.
|
||||
* @return boolean
|
||||
* @throws CakeException when attempting to bind a translating called name. This is not allowed
|
||||
* @return bool
|
||||
* @throws CakeException when attempting to bind a translating called name. This is not allowed
|
||||
* as it shadows Model::$name.
|
||||
*/
|
||||
public function bindTranslation(Model $Model, $fields, $reset = true) {
|
||||
|
@ -551,7 +589,8 @@ class TranslateBehavior extends ModelBehavior {
|
|||
$RuntimeModel = $this->translateModel($Model);
|
||||
$default = array(
|
||||
'className' => $RuntimeModel->alias,
|
||||
'foreignKey' => 'foreign_key'
|
||||
'foreignKey' => 'foreign_key',
|
||||
'order' => 'id'
|
||||
);
|
||||
|
||||
foreach ($fields as $key => $value) {
|
||||
|
@ -567,10 +606,9 @@ class TranslateBehavior extends ModelBehavior {
|
|||
__d('cake_dev', 'You cannot bind a translation named "name".')
|
||||
);
|
||||
}
|
||||
|
||||
$this->_removeField($Model, $field);
|
||||
|
||||
if (is_null($association)) {
|
||||
if ($association === null) {
|
||||
if ($reset) {
|
||||
$this->runtime[$Model->alias]['fields'][] = $field;
|
||||
} else {
|
||||
|
@ -579,6 +617,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
} else {
|
||||
if ($reset) {
|
||||
$this->runtime[$Model->alias]['fields'][$field] = $association;
|
||||
$this->runtime[$Model->alias]['restoreFields'][] = $field;
|
||||
} else {
|
||||
$this->settings[$Model->alias][$field] = $association;
|
||||
}
|
||||
|
@ -593,7 +632,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
}
|
||||
}
|
||||
$associations[$association] = array_merge($default, array('conditions' => array(
|
||||
'model' => $Model->alias,
|
||||
'model' => $Model->name,
|
||||
$RuntimeModel->displayField => $field
|
||||
)));
|
||||
}
|
||||
|
@ -608,7 +647,9 @@ class TranslateBehavior extends ModelBehavior {
|
|||
/**
|
||||
* Update runtime setting for a given field.
|
||||
*
|
||||
* @param Model $Model Model using this behavior
|
||||
* @param string $field The field to update.
|
||||
* @return void
|
||||
*/
|
||||
protected function _removeField(Model $Model, $field) {
|
||||
if (array_key_exists($field, $this->settings[$Model->alias])) {
|
||||
|
@ -628,10 +669,10 @@ class TranslateBehavior extends ModelBehavior {
|
|||
* Unbind translation for fields, optionally unbinds hasMany association for
|
||||
* fake field
|
||||
*
|
||||
* @param Model $Model instance of model
|
||||
* @param Model $Model using this behavior of model
|
||||
* @param string|array $fields string with field, or array(field1, field2=>AssocName, field3), or null for
|
||||
* unbind all original translations
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function unbindTranslation(Model $Model, $fields = null) {
|
||||
if (empty($fields) && empty($this->settings[$Model->alias])) {
|
||||
|
@ -657,7 +698,7 @@ class TranslateBehavior extends ModelBehavior {
|
|||
|
||||
$this->_removeField($Model, $field);
|
||||
|
||||
if (!is_null($association) && (isset($Model->hasMany[$association]) || isset($Model->__backAssociation['hasMany'][$association]))) {
|
||||
if ($association !== null && (isset($Model->hasMany[$association]) || isset($Model->__backAssociation['hasMany'][$association]))) {
|
||||
$associations[] = $association;
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue