public function removeDuplicates($strict = false) {
		$field = $strict ? 'message' : 'summary';

		$query = $this->find();
		$options = [
			'fields' => ['type', $field, 'count' => $query->func()->count('*')],
			'conditions' => [],
			'group' => ['type', $field],
			//'having' => $this->alias . '__count > 0',
			//'order' => ['created' => 'DESC']
		];
		$logs = $query->find('all', $options)->disableHydration()->toArray();

		$count = 0;
		foreach ($logs as $key => $log) {
			if ($log['count'] <= 1) {
				continue;
			}
			$options = [
				'fields' => ['id'],
				'keyField' => 'id',
				'valueField' => 'id',
				'conditions' => [
					'type' => $log['type'],
					$field => $log[$field],
				],
				'order' => ['created' => 'DESC']
			];
			$entries = $this->find('list', $options)->toArray();

			// keep the newest entry
			$keep = array_shift($entries);
			if ($entries) {
				$this->deleteAll(['id IN' => $entries]);
			}
			$count += $this->updateAll(['count = count + ' . count($entries)], ['id' => $keep]);
		}

		return $count;
	}
public function removeDuplicates($strict = false) {
		$field = $strict ? 'message' : 'summary';

		$query = $this->find();
		$options = [
			'fields' => ['type', $field, 'count' => $query->func()->count('*')],
			'conditions' => [],
			'group' => ['type', $field],
			//'having' => $this->alias . '__count > 0',
			//'order' => ['created' => 'DESC']
		];
		$logs = $query->find('all', $options)->disableHydration()->toArray();

		$count = 0;
		foreach ($logs as $key => $log) {
			if ($log['count'] <= 1) {
				continue;
			}
			$options = [
				'fields' => ['id'],
				'keyField' => 'id',
				'valueField' => 'id',
				'conditions' => [
					'type' => $log['type'],
					$field => $log[$field],
				],
				'order' => ['created' => 'DESC']
			];
			$entries = $this->find('list', $options)->toArray();

			// keep the newest entry
			$keep = array_shift($entries);
			if ($entries) {
				$this->deleteAll(['id IN' => $entries]);
			}
			$count += $this->updateAll(['count = count + ' . count($entries)], ['id' => $keep]);
		}

		return $count;
	}
public function removeDuplicates ( $ strict = false ) { $ field = $ strict ? 'message' : 'summary' ; $ query = $ this -> find ( ) ; $ options = [ 'fields' => [ 'type' , $ field , 'count' => $ query -> func ( ) -> count ( '*' ) ] , 'conditions' => [ ] , 'group' => [ 'type' , $ field ] , //'having' => $this->alias . '__count > 0', //'order' => ['created' => 'DESC'] ] ; $ logs = $ query -> find ( 'all' , $ options ) -> disableHydration ( ) -> toArray ( ) ; $ count = 0 ; foreach ( $ logs as $ key => $ log ) { if ( $ log [ 'count' ] <= 1 ) { continue ; } $ options = [ 'fields' => [ 'id' ] , 'keyField' => 'id' , 'valueField' => 'id' , 'conditions' => [ 'type' => $ log [ 'type' ] , $ field => $ log [ $ field ] , ] , 'order' => [ 'created' => 'DESC' ] ] ; $ entries = $ this -> find ( 'list' , $ options ) -> toArray ( ) ; // keep the newest entry $ keep = array_shift ( $ entries ) ; if ( $ entries ) { $ this -> deleteAll ( [ 'id IN' => $ entries ] ) ; } $ count += $ this -> updateAll ( [ 'count = count + ' . count ( $ entries ) ] , [ 'id' => $ keep ] ) ; } return $ count ; }
Remove duplicates and leave only the newest entry
Also stores the new total "number" of this message in the remaining one

@param bool $strict
@return int
Remove duplicates and leave only the newest entry Also stores the new total number of this message in the remaining one