/**
  * Extracts files from the archive and stores the media as temporary-zipped-media nodes.
  *
  * @throws Exception
  * @param $params
  * @return array Array of created nodes
  */
 protected function _extractArchive($params)
 {
     $nodes = array();
     $workdir = FileSystemUtils::createWorkingDirectory();
     try {
         list($sourceFile, $sourceFileName) = $this->getSourceFile($params);
         $zip = zip_open($sourceFile);
         if (is_resource($zip)) {
             while ($zip_entry = zip_read($zip)) {
                 $entryFileName = basename(zip_entry_name($zip_entry));
                 $entryFile = rtrim($workdir, '/') . '/' . $entryFileName;
                 if (preg_match('/^\\./', $entryFileName)) {
                     continue;
                 }
                 $path = pathinfo($entryFile);
                 if (empty($path['extension'])) {
                     continue;
                 }
                 try {
                     // Create the file
                     if (zip_entry_open($zip, $zip_entry, 'r')) {
                         if ($fd = @fopen($entryFile, 'w+')) {
                             fwrite($fd, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)));
                             fclose($fd);
                             $nodeRef = new NodeRef($this->NodeRefService->oneFromAspect('@temporary-zipped-media')->getElement(), SlugUtils::createSlug($entryFileName));
                             $nodeRef = $this->NodeService->generateUniqueNodeRef($nodeRef, null, true);
                             // create node
                             $node = $nodeRef->generateNode();
                             $this->NodeMapper->defaultsOnNode($node);
                             if ($node != null) {
                                 $node->Title = $entryFileName;
                                 $node->Slug = SlugUtils::createSlug($entryFileName);
                                 $this->getErrors()->throwOnError();
                                 $this->RegulatedNodeService->quickAdd($node);
                                 $node = $this->RegulatedNodeService->getByNodeRef($node->getNodeRef(), new NodePartials());
                                 // add the original media
                                 $file_params = $params;
                                 $file_params['File'] = $entryFileName;
                                 $file_params['NodeSlug'] = $node->Slug;
                                 $file_params['ElementSlug'] = 'temporary-zipped-media';
                                 $file_params['_uploadedFiles']['file'] = new UploadedFile($entryFileName, $entryFile, zip_entry_filesize($zip_entry), FileSystemUtils::getMimetype($path['extension']), 0);
                                 $this->addOriginal($file_params);
                                 $this->_buildCmsThumbnail($node);
                                 $node = $this->RegulatedNodeService->getByNodeRef($node->getNodeRef(), new NodePartials('all', '#original.fields'));
                                 $nodes[] = $node;
                                 @unlink($entryFile);
                             }
                         }
                         zip_entry_close($zip_entry);
                     }
                 } catch (Exception $e) {
                     @unlink($entryFile);
                     throw $e;
                 }
             }
             zip_close($zip);
         } else {
             throw new Exception($this->_zipFileErrMsg($zip));
         }
     } catch (Exception $e) {
         // clean up
         //@unlink($sourceFile);
         throw $e;
     }
     return $nodes;
 }