作者 Karson

!24 修复1062 Duplicate entry 'addon/index' for key 'name'

Merge pull request !24 from private/master
@@ -264,10 +264,24 @@ class Menu extends Command @@ -264,10 +264,24 @@ class Menu extends Command
264 $comment = preg_replace(array('/^\/\*\*(.*)[\n\r\t]/u', '/[\s]+\*\//u', '/\*\s@(.*)/u', '/[\s|\*]+/u'), '', $comment); 264 $comment = preg_replace(array('/^\/\*\*(.*)[\n\r\t]/u', '/[\s]+\*\//u', '/\*\s@(.*)/u', '/[\s|\*]+/u'), '', $comment);
265 265
266 $title = $comment ? $comment : ucfirst($n->name); 266 $title = $comment ? $comment : ucfirst($n->name);
267 -  
268 - $ruleArr[] = array('pid' => $pid, 'name' => $name . "/" . strtolower($n->name), 'icon' => 'fa fa-circle-o', 'title' => $title, 'ismenu' => 0, 'status' => 'normal'); 267 +
  268 + //获取主键,作为AuthRule更新依据
  269 + $id = $this->getAuthRulePK($name . "/" . strtolower($n->name));
  270 +
  271 + $ruleArr[] = array('id' => $id, 'pid' => $pid, 'name' => $name . "/" . strtolower($n->name), 'icon' => 'fa fa-circle-o', 'title' => $title, 'ismenu' => 0, 'status' => 'normal');
269 } 272 }
270 $this->model->saveAll($ruleArr); 273 $this->model->saveAll($ruleArr);
271 } 274 }
272 275
  276 + //获取主键
  277 + protected function getAuthRulePK($name) {
  278 + if (!empty($name))
  279 + {
  280 + return $this->model
  281 + ->where('name', $name)
  282 + ->value('id');
  283 +
  284 + }
  285 + }
  286 +
273 } 287 }