Hallo.
Wie kann es sein das bei jedem Aufruf eines bestimmten Models / Objekts immer das Feld modified geändert wird, obwohl NICHTS geöndert wird !?
ich würde gerne die afterSave()-Funktion nutzen, aber nicht bei jedem Aufruf ...
thx
Empfehlungen: Erweiterte Suche
<?php
class Shop extends AppModel {
public $actsAs = array('FieldMaxLengthValidator', 'Transaction');
const NOTIFY_MAIL_TYPE_DEFAULT = 0;
const NOTIFY_MAIL_TYPE_MINIMAL = 1;
public static function getNotifyMailTypesArray() {
return array(
self::NOTIFY_MAIL_TYPE_DEFAULT => t('Volle Info (standard)'),
self::NOTIFY_MAIL_TYPE_MINIMAL => t('Minimal'),
);
}
public static function getNotifyMailTypeName($type) {
$types = self::getNotifyMailTypesArray();
return isset($types[$type]) ? $types[$type] : $type;
}
public $validate = array(
'user_id' => array(
'positiveInteger' => array(
'rule' => array('userDefined', 'CustomValidation', 'positiveInteger', false),
'allowEmpty' => false,
)),....
);
public function afterFind($results) {
ClassLoader::importComponent("AmazonS3");
parent::afterFind($results);
foreach ($results as $key => &$row) {
if (isset($row[$this->alias]['id'])) {
$key = AWS_S3_URL_HTTP_PUBLIC."/";
$key .= AmazonS3Component::buildShopLogoKey($row[$this->alias]['id']);
$row[$this->alias]['image_url_icon'] = $key."a.png";
$row[$this->alias]['image_url_small'] = $key."b.png";
$row[$this->alias]['image_url_large'] = $key."c.png";
}
}
return $results;
}
public function beforeValidate($options = array()) {
if(!empty($this->data['Shop']['merchant_notify_mail'])) {
$this->validate['merchant_notify_mail_address'] = array(
'email' => array(
'rule' => array('email'),
'allowEmpty' => false,
));
}
if(!empty($this->data['Shop']['merchant_notify_http'])) {
$this->validate['merchant_notify_http_url'] = array(
'minLength' => array(
'rule' => array('userDefined', 'CustomValidation', 'minLength', 6),
'allowEmpty' => false,
));
}
return parent::beforeValidate($options);
}
public function bindUser() {
$this->bindModel(array('belongsTo' => array('User')));
}
public function bindCountry() {
$this->bindModel(array('belongsTo' => array('Country')));
}
public function getNewShopNumber() {
$lastInsert = $this->find('first', array('order' => 'shop_number desc', 'fields'=>array('shop_number')));
$number = $lastInsert['Shop']['shop_number'] + 1;
if(!empty($lastInsert['Shop']['shop_number']) && $lastInsert['Shop']['shop_number'] >= 10001) {
return $lastInsert['Shop']['shop_number'] + 1;
} else {
return 10001;
}
}
// ####################################### SOLR - Shop Synchro #####################################################
/**
* Nach Änderungen muss überprüft werden, ob ein Shop auf is_active=0 oder 1 gesetzt worden ist.
*/
public function afterSave($created){
// TODO: afterDelete. --> Shop aus dem Index entfernen
if( !empty($this->id) ){
$is_active = $this->data['Shop']['is_active'];
if( $is_active ){
// Überprüfen ob Shop schon im Index ist
if(!$this->isShopInIndex($this->id)){
// Ist nicht im Index --> Starte Import
try{
App::import('Component', 'SolrSearch');
$solr = new SolrSearchComponent();
$solr->importShop($this->id);
}catch(Exception $e){
$this->log('Konnte Solr Instanz nicht erzeugen. ShopModel');
}
}
}elseif( !$is_active ){
// Überprüfe ob der Shop nicht mehr in Index ist
if($this->isShopInIndex($this->id)){
// Ist im Index --> Lösche diesen Shop aus dem Index
try{
App::import('Component', 'SolrSearch');
$solr = new SolrSearchComponent();
$solr->deleteShop($this->id);
}catch(Exception $e){
$this->log('Konnte Solr Instanz nicht erzeugen. ShopModel');
}
}
}
}
}
/**
* Entferne jeden Shop direkt aus dem Index wenn dieser gelöscht wurde !
*
* @return unknown
*/
public function afterDelete(){
if( !empty($this->id) ){
if($this->isShopInIndex($this->id)){
try{
App::import('Component', 'SolrSearch');
$solr = new SolrSearchComponent();
$solr->deleteShop($this->id);
}catch(Exception $e){
$this->log('Konnte Solr Instanz nicht erzeugen. ShopModel');
}
}
}
// Gib immer true zurück, da sonst evlt der Shop nicht wirkich gelöscht wird.
return true;
}
/**
* Überprüft ob Shop im SuchIndex vorhanden ist.
*
* @param ShopId $id
* return boolean
*/
public function isShopInIndex($shopId){
try{
App::import('Component', 'SolrSearch');
$solr = new SolrSearchComponent();
return $result = $solr->isShopInIndex($shopId);
}catch(Exception $e){
$this->log('Konnte Solr Instanz nicht erzeugen. ShopModel');
}
}
}
?>
Mitglieder in diesem Forum: Google [Bot] und 1 Gast