/**
  * Create a new service for a file and a server.
  *
  * @param Omeka_record $file The file.
  * @param Omeka_record $server The server.
  *
  * @return Omeka_record $edition The new service.
  */
 public function createFromFileAndServer($file, $server)
 {
     // Get parent item.
     $item = $file->getItem();
     // If the parent item already has a service, break;
     if ($this->findByItem($item)) {
         return false;
     }
     // Create service.
     $wms = new NeatlineMapsService($item);
     $wms->address = $server->getWmsAddress();
     $wms->layers = nlwms_layerName($server, $file);
     $wms->save();
     return $wms;
 }
 /**
  * Try to post new file to Geoserver.
  *
  * @param File $file The file.
  *
  * @return void.
  */
 public function afterInsertFile($file)
 {
     // Is the image a tiff?
     if ($file->getMimeType() == 'image/tiff') {
         // Get the active server.
         $server = $this->serversTable->getActiveServer();
         // Throw file at Geoserver.
         if ($server && _putFileToGeoserver($file, $server)) {
             // Get parent item and WMS.
             $item = $file->getItem();
             $wms = $this->servicesTable->findByItem($item);
             // If no WMS exists, create one for the file that
             // was just uploaded to Geoserver.
             if (!$wms) {
                 $this->servicesTable->createFromFileAndServer($file, $server);
             } else {
                 if ($wms->address == $server->getWmsAddress()) {
                     // If a WMS already exists and the address is the
                     // same as the address of the active server, append
                     // the new layer to the active layers list.
                     $wms->layers .= ',' . nlwms_layerName($server, $file);
                     $wms->save();
                 }
             }
         }
     }
 }