Ejemplo n.º 1
0
 /**
  * Loads the patch files from TeraWurflConfig::PATCH_FILE
  * @return Bool Success
  */
 public function loadPatches()
 {
     if (!TeraWurflConfig::$PATCH_ENABLE) {
         return true;
     }
     $this->timepatch = microtime(true);
     // Explode the patchfile string into an array of patch files (normally just one file)
     $patches = explode(';', TeraWurflConfig::$PATCH_FILE);
     foreach ($patches as $patch) {
         $patch_devices = array();
         $this->wurfl->toLog("Loading patch: " . $patch, LOG_WARNING);
         $patch_parser = TeraWurflXMLParser::getInstance();
         $patch_parser->open(TeraWurfl::absoluteDataDir() . $patch, TeraWurflXMLParser::$TYPE_PATCH);
         $patch_parser->process($patch_devices);
         foreach ($patch_devices as $id => &$device) {
             if ($this->validID($id)) {
                 // Merge this device on top of the existing device
                 TeraWurfl::mergeCapabilities($this->devices[$id], $device);
                 $this->patchMergedDevices++;
             } else {
                 // Add this new device to the table
                 $this->devices[$id] = $device;
                 $this->patchAddedDevices++;
             }
         }
         unset($this->parser);
     }
     return true;
 }
 /**
  * Loads the patch files from TeraWurflConfig::PATCH_FILE
  * @return bool Success
  */
 public function loadPatches()
 {
     if (!TeraWurflConfig::$PATCH_ENABLE) {
         return true;
     }
     $this->timepatch = microtime(true);
     // Explode the patchfile string into an array of patch files (normally just one file)
     $patches = explode(';', TeraWurflConfig::$PATCH_FILE);
     foreach ($patches as $patch) {
         $patch_devices = array();
         $this->wurfl->toLog("Loading patch: " . $patch, LOG_WARNING);
         $patch_parser = TeraWurflXMLParser::getInstance();
         $patch_parser->open(TeraWurfl::absoluteDataDir() . $patch, TeraWurflXMLParser::$TYPE_PATCH);
         $patch_parser->process($patch_devices);
         foreach ($patch_devices as $id => &$device) {
             // if the fall_back is blank, or equal to it's id, or the fall_back ID doesn't exist in the device table or this patch file,
             // then it will cause the API to fail.  We'll skip this device and report the error.  There is also the possibility that the
             // device has a valid fallback in a patch file that hasn't been prosessed yet, but this is not worth trying to detect.
             if (!isset($device['fall_back']) || $id == $device['fall_back'] || !$this->validID($device['fall_back']) && !in_array($device['fall_back'], $patch_devices)) {
                 $this->errors[] = "The device '{$id}' from patch file '{$patch}' has an invalid fall_back device ID and has been skipped.";
                 $this->wurfl->toLog("The device '{$id}' from patch file '{$patch}' has an invalid fall_back device ID and has been skipped.", LOG_WARNING);
                 continue;
             }
             if ($this->validID($id)) {
                 // Merge this device on top of the existing device
                 TeraWurfl::mergeCapabilities($this->devices[$id], $device);
                 $this->patchMergedDevices++;
             } else {
                 // Add this new device to the table
                 $this->devices[$id] = $device;
                 $this->patchAddedDevices++;
             }
         }
         unset($this->parser);
     }
     return true;
 }