示例#1
0
 public function createFromITunesScraper($appinfo, $iconsPreSaved = false)
 {
     $bean = new ApplicationBean();
     $bean->itunes_id = $appinfo->getITunesID();
     $bean->name = $appinfo->getName();
     $bean->releasedate = $appinfo->getReleaseDate();
     $bean->seller = $appinfo->getSeller();
     $bean->company = $appinfo->getCompany() ?: $bean->seller;
     $bean->size = $appinfo->getSize();
     $bean->price = $appinfo->getPrice();
     $bean->description = $appinfo->getDescription();
     $bean->languages = $appinfo->getLanguages();
     $bean->requirements = $appinfo->getRequirements();
     $smallicon = $appinfo->getITunesID() . 'icon-57x57.png';
     $bigicon = $appinfo->getITunesID() . 'icon-100x100.png';
     if ($iconsPreSaved || $this->saveIconsLocally($appinfo->getIconUrlPNG(), $smallicon, $bigicon)) {
         $bean->smallicon_url = '%BASE_URL%/appimages/icons/' . $smallicon;
         $bean->bigicon_url = '%BASE_URL%/appimages/icons/' . $bigicon;
     }
     $bean->set('date_added', 'NOW()', true);
     $bean->set('last_updated', 'NOW()', true);
     $catname = $appinfo->getCategory() ?: 'Unknown';
     $acm = AppCategoryModel::getInstance();
     $cat = $acm->getByName($catname);
     if (!$cat) {
         $acm->create($catname);
         if (!($cat = $acm->getByName($catname))) {
             return false;
         }
     }
     $bean->category_id = $cat->id;
     try {
         $bean->insert();
     } catch (QueryFailedException $e) {
         return false;
     }
     $shots = $appinfo->getScreenshots();
     if ($shots) {
         if (!($bean = $this->getDetailsByITunesID($appinfo->getITunesID(), false))) {
             return false;
         }
         $sm = ScreenshotModel::getInstance();
         $sm->setScreenshots($bean->id, $bean->itunes_id, $shots);
     }
     $this->indexName($bean->name, $bean->id);
     $this->cm->clearGroup('applist');
     return true;
 }