예제 #1
0
 /**
  * Extract a packagefile object from the registry
  * @return \Pyrus\PackageFile\v2
  */
 function toPackageFile($package, $channel)
 {
     if (!static::existsRegistry($this->_path)) {
         throw new Exception('Error: no existing SQLite3 registry for ' . $this->_path);
     }
     if (!$this->exists($package, $channel)) {
         throw new Exception('Cannot retrieve package file object ' . 'for package ' . $channel . '/' . $package . ', it is not installed');
     }
     $ret = new \Pyrus\PackageFile\v2();
     $ret->name = $this->info($package, $channel, 'name');
     $ret->channel = $channel;
     $ret->summary = $this->info($package, $channel, 'summary');
     $ret->description = $this->info($package, $channel, 'description');
     $ret->type = $this->info($package, $channel, 'packagetype');
     $sql = 'SELECT * FROM maintainers
             WHERE packages_name = :name AND packages_channel = :channel';
     $database = static::getRegistry($this->_path);
     $stmt = $database->prepare($sql);
     $stmt->bindValue(':name', strtolower($package));
     $stmt->bindValue(':channel', $channel);
     $result = @$stmt->execute();
     if (!$result) {
         throw new Exception('Could not retrieve package file object' . ' for package ' . $channel . '/' . $ret->name . ', no maintainers registered');
     }
     while ($maintainer = $result->fetchArray(SQLITE3_ASSOC)) {
         $ret->maintainer[$maintainer['user']]->name($maintainer['name'])->role($maintainer['role'])->email($maintainer['email'])->active($maintainer['active']);
     }
     $stmt->close();
     $ret->date = $this->info($package, $channel, 'date');
     // FIXME why are we querying the same info twice ?
     if ($a = $this->info($package, $channel, 'time')) {
         $ret->time = $this->info($package, $channel, 'time');
     }
     $ret->version['release'] = $this->info($package, $channel, 'version');
     $ret->version['api'] = $this->info($package, $channel, 'apiversion');
     $ret->stability['release'] = $this->info($package, $channel, 'stability');
     $ret->stability['api'] = $this->info($package, $channel, 'apistability');
     $uri = $this->info($package, $channel, 'licenseuri');
     $path = $this->info($package, $channel, 'licensepath');
     $license = $this->info($package, $channel, 'license');
     if ($uri) {
         $ret->rawlicense = array('attribs' => array('uri' => $uri), '_content' => $license);
     } elseif ($path) {
         $ret->rawlicense = array('attribs' => array('path' => $path), '_content' => $license);
     } else {
         $ret->license = $license;
     }
     $ret->notes = $this->info($package, $channel, 'releasenotes');
     $sql = 'SELECT * FROM files
             WHERE packages_name = :name AND packages_channel = :channel';
     $stmt = $database->prepare($sql);
     $stmt->bindValue(':name', strtolower($package));
     $stmt->bindValue(':channel', $channel);
     $result = @$stmt->execute();
     if (!$result) {
         throw new Exception('Could not retrieve package file object' . ' for package ' . $channel . '/' . $ret->name . ', no files registered');
     }
     while ($file = $result->fetchArray(SQLITE3_ASSOC)) {
         $ret->files[$file['origpath']] = array_merge(array('attribs' => array('role' => $file['role'])), unserialize($file['tasks']));
         if ($file['baseinstalldir']) {
             $ret->setFileAttribute($file['origpath'], 'baseinstalldir', $file['baseinstalldir']);
         }
         if ($file['md5sum'] != md5('')) {
             $ret->setFileAttribute($file['origpath'], 'md5sum', $file['md5sum']);
         }
     }
     $stmt->close();
     $sql = 'SELECT dirname, baseinstall FROM baseinstalldirs
             WHERE packages_name = :name AND packages_channel = :channel';
     $stmt = $database->prepare($sql);
     $stmt->bindValue(':name', strtolower($package));
     $stmt->bindValue(':channel', $channel);
     $result = @$stmt->execute();
     if (!$result) {
         throw new Exception('Could not retrieve package file object' . ' for package ' . $channel . '/' . $ret->name . ', no files registered');
     }
     $dirs = array();
     while ($dir = $result->fetchArray(SQLITE3_ASSOC)) {
         $dirs[$dir['dirname']] = $dir['baseinstall'];
     }
     $ret->setBaseInstallDirs($dirs);
     $stmt->close();
     $this->fetchCompatible($ret);
     $this->fetchDeps($ret);
     $ret->release = null;
     $sql = 'SELECT * FROM configureoptions
             WHERE
                 packages_name = "' . $database->escapeString(strtolower($package)) . '" AND
                 packages_channel = "' . $database->escapeString($channel) . '"';
     $a = $database->query($sql);
     while ($option = $a->fetchArray(SQLITE3_ASSOC)) {
         $ret->installrelease->configureoption[$option['name']]->prompt($option['prompt'])->default($option['defaultValue']);
     }
     return $ret;
 }