From e578b034896d1ef9268493d9e4ca35029d8b4ed3 Mon Sep 17 00:00:00 2001 From: Lukianenko Dmytro Date: Mon, 2 Nov 2015 22:16:39 +0200 Subject: [PATCH] update lib resource.php --- assets/libs/resourse.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/assets/libs/resourse.php b/assets/libs/resourse.php index 539de1c878..985118f328 100644 --- a/assets/libs/resourse.php +++ b/assets/libs/resourse.php @@ -1,5 +1,10 @@ field; } - private function checkAlias($alias){ + private function checkAlias($alias, $i=1){ if($this->modx->config['friendly_urls']){ $flag = false; $_alias = $this->modx->db->escape($alias); @@ -402,14 +408,14 @@ private function checkAlias($alias){ $flag = $this->modx->db->getValue($this->modx->db->select('id', $this->_table['site_content'], "alias='{$_alias}'", '', 1)); } if(($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)){ - $suffix = substr($alias, -2); + /*$suffix = substr($alias, -2); if(preg_match('/-(\d+)/',$suffix,$tmp) && isset($tmp[1]) && (int)$tmp[1]>1){ $suffix = (int)$tmp[1] + 1; $alias = substr($alias, 0, -2) . '-'. $suffix; }else{ $alias .= '-2'; - } - $alias = $this->checkAlias($alias); + }*/ + $alias = $this->checkAlias($alias.'-'.$i,$i+1); } } return $alias; @@ -452,21 +458,25 @@ public function save($fire_events = null,$clearCache = false){ if($this->newDoc) $this->id = $this->modx->db->getInsertId(); foreach($fld as $key=>$value){ - if ($value=='') continue; + #if ($value=='') continue; if ($this->tv[$key]!=''){ $fields = array( 'tmplvarid' => $this->tv[$key], 'contentid' => $this->id, 'value' => $this->modx->db->escape($value), ); + $rs = $this->modx->db->select('value', $this->_table['site_tmplvar_contentvalues'], "contentid = '{$fields['contentid']}' AND tmplvarid = '{$fields['tmplvarid']}'"); - if ($row = $this->modx->db->getRow($rs)) { + + if ( $this->modx->db->getRecordCount($rs) > 0 ) { + $row = $this->modx->db->getRow($rs); if ($row['value'] != $value) { $this->modx->db->update($fields, $this->_table['site_tmplvar_contentvalues'], "contentid = '{$fields['contentid']}' AND tmplvarid = '{$fields['tmplvarid']}'"); } }else{ $this->modx->db->insert($fields, $this->_table['site_tmplvar_contentvalues']); } + } } $this->invokeEvent('OnDocFormSave',array (