Model/Behavior/DuplicatableBehavior.php
public function duplicate(Model $Model, $data, $config = array()) {
		$config = array_merge($this->settings[$Model->alias], $config);

		if (empty($Model->id) && empty($data[$Model->alias][$Model->primaryKey])) {
			throw new Exception(__d('common', "Missing primary key for duplicatable '%s' data", $Model->name));
		}

		$id = $Model->id ? $Model->id : $data[$Model->alias][$Model->primaryKey];
		$conditions = array($Model->primaryKey => $id) + (array) $this->settings[$Model->alias]['scope'];

		if (
			!empty($this->settings[$Model->alias]['scope'])
			&& !$Model->find('count', compact('conditions'))
		) {
			return false;
		}

		$duplicateData = array(
			$config['duplicatedKey'] => $id,
			$config['duplicatedModel'] => (!empty($Model->plugin) ? $Model->plugin . '.' : '') . $Model->name
		);

		$DuplicateModel = ClassRegistry::init($config['model']);
		$DuplicateModel->create();

		$duplicateRecord = $DuplicateModel->find('first', array('conditions' => $duplicateData, 'recursive' => -1));
		if (!empty($duplicateRecord)) {
			$DuplicateModel->id = $duplicateRecord[$DuplicateModel->alias][$DuplicateModel->primaryKey];
		}

		foreach ((array) $config['mapFields'] as $field => $path) {
			$value = Hash::extract($data, $path);
			$duplicateData[$field] = array_pop($value);
			if (
				!empty($duplicateRecord[$DuplicateModel->alias][$field])
				&& $duplicateRecord[$DuplicateModel->alias][$field] === $duplicateData[$field]
			) {
				unset($duplicateData[$field]);
			}
		}

		if (
			(empty($duplicateRecord) || 1 < count($duplicateData))
			&& (!empty($DuplicateModel->id) || $DuplicateModel->create($duplicateData))
			&& !$DuplicateModel->save()
		) {
			return false;
		}

		return true;
	}
public function duplicate(Model $Model, $data, $config = array()) {
		$config = array_merge($this->settings[$Model->alias], $config);

		if (empty($Model->id) && empty($data[$Model->alias][$Model->primaryKey])) {
			throw new Exception(__d('common', "Missing primary key for duplicatable '%s' data", $Model->name));
		}

		$id = $Model->id ? $Model->id : $data[$Model->alias][$Model->primaryKey];
		$conditions = array($Model->primaryKey => $id) + (array) $this->settings[$Model->alias]['scope'];

		if (
			!empty($this->settings[$Model->alias]['scope'])
			&& !$Model->find('count', compact('conditions'))
		) {
			return false;
		}

		$duplicateData = array(
			$config['duplicatedKey'] => $id,
			$config['duplicatedModel'] => (!empty($Model->plugin) ? $Model->plugin . '.' : '') . $Model->name
		);

		$DuplicateModel = ClassRegistry::init($config['model']);
		$DuplicateModel->create();

		$duplicateRecord = $DuplicateModel->find('first', array('conditions' => $duplicateData, 'recursive' => -1));
		if (!empty($duplicateRecord)) {
			$DuplicateModel->id = $duplicateRecord[$DuplicateModel->alias][$DuplicateModel->primaryKey];
		}

		foreach ((array) $config['mapFields'] as $field => $path) {
			$value = Hash::extract($data, $path);
			$duplicateData[$field] = array_pop($value);
			if (
				!empty($duplicateRecord[$DuplicateModel->alias][$field])
				&& $duplicateRecord[$DuplicateModel->alias][$field] === $duplicateData[$field]
			) {
				unset($duplicateData[$field]);
			}
		}

		if (
			(empty($duplicateRecord) || 1 < count($duplicateData))
			&& (!empty($DuplicateModel->id) || $DuplicateModel->create($duplicateData))
			&& !$DuplicateModel->save()
		) {
			return false;
		}

		return true;
	}
public function duplicate ( Model $ Model , $ data , $ config = array ( ) ) { $ config = array_merge ( $ this -> settings [ $ Model -> alias ] , $ config ) ; if ( empty ( $ Model -> id ) && empty ( $ data [ $ Model -> alias ] [ $ Model -> primaryKey ] ) ) { throw new Exception ( __d ( 'common' , "Missing primary key for duplicatable '%s' data" , $ Model -> name ) ) ; } $ id = $ Model -> id ? $ Model -> id : $ data [ $ Model -> alias ] [ $ Model -> primaryKey ] ; $ conditions = array ( $ Model -> primaryKey => $ id ) + ( array ) $ this -> settings [ $ Model -> alias ] [ 'scope' ] ; if ( ! empty ( $ this -> settings [ $ Model -> alias ] [ 'scope' ] ) && ! $ Model -> find ( 'count' , compact ( 'conditions' ) ) ) { return false ; } $ duplicateData = array ( $ config [ 'duplicatedKey' ] => $ id , $ config [ 'duplicatedModel' ] => ( ! empty ( $ Model -> plugin ) ? $ Model -> plugin . '.' : '' ) . $ Model -> name ) ; $ DuplicateModel = ClassRegistry :: init ( $ config [ 'model' ] ) ; $ DuplicateModel -> create ( ) ; $ duplicateRecord = $ DuplicateModel -> find ( 'first' , array ( 'conditions' => $ duplicateData , 'recursive' => - 1 ) ) ; if ( ! empty ( $ duplicateRecord ) ) { $ DuplicateModel -> id = $ duplicateRecord [ $ DuplicateModel -> alias ] [ $ DuplicateModel -> primaryKey ] ; } foreach ( ( array ) $ config [ 'mapFields' ] as $ field => $ path ) { $ value = Hash :: extract ( $ data , $ path ) ; $ duplicateData [ $ field ] = array_pop ( $ value ) ; if ( ! empty ( $ duplicateRecord [ $ DuplicateModel -> alias ] [ $ field ] ) && $ duplicateRecord [ $ DuplicateModel -> alias ] [ $ field ] === $ duplicateData [ $ field ] ) { unset ( $ duplicateData [ $ field ] ) ; } } if ( ( empty ( $ duplicateRecord ) || 1 < count ( $ duplicateData ) ) && ( ! empty ( $ DuplicateModel -> id ) || $ DuplicateModel -> create ( $ duplicateData ) ) && ! $ DuplicateModel -> save ( ) ) { return false ; } return true ; }
Clone model's data.

@param Model $Model
@param array $options
@return [type]
Clone model s data .