示例#1
0
文件: pm.php 项目: frdl/webfan
 public function find($o)
 {
     if (!isset($this->argtoks['arguments'][1]) || intval($this->argtoks['arguments'][1]['pos']) !== 2) {
         return $this->wrongArgumentCount();
     }
     $this->packagefullname = str_replace(array('"', "'"), array('', ''), $this->argtoks['arguments'][1]['cmd']);
     try {
         $this->F = new \frdl\ApplicationComposer\Repos\Fetch($o);
         $this->result->searchresults = $this->F->search($this->packagefullname);
         $this->result->searchresults = array_unique($this->result->searchresults);
     } catch (\Exception $e) {
         \webdof\wResponse::status(409);
         $this->result->out = $e->getMessage();
         return;
     }
     if (isset($this->argtoks['flags']['s']) && true === $this->aSess['isAdmin']) {
         $p = new \frdl\ApplicationComposer\Package(array(), \frdl\xGlobal\webfan::db()->settings(), $this->db);
         $p->db()->begin();
         foreach ($this->result->searchresults as $num => $s) {
             if (is_array($s)) {
                 foreach ($s as $num2 => $s2) {
                     $v = explode('/', $s2->name);
                     if (2 === count($v) && !$p->find($v[0], $v[1])) {
                         $p->vendor = $v[0];
                         $p->package = $v[1];
                         $p->url = $s2->url;
                         $p->description = $s2->description;
                         $p->time_last_fetch_info = time();
                         $p->create();
                     }
                 }
             } else {
                 $v = explode('/', $s->name);
                 if (2 === count($v) && !$p->find($v[0], $v[1])) {
                     $p->vendor = $v[0];
                     $p->package = $v[1];
                     $p->url = $s->url;
                     $p->description = $s->description;
                     $p->time_last_fetch_info = time();
                     $p->create();
                 }
             }
         }
         $p->db()->commit();
     }
     $this->result->out = 'OK';
 }