コード例 #1
0
 public function postEditCollection($userId, $collectionId, Zipper $zipper, PathBuilder $pathBuilder, PostEditCollectionRequest $request, BlueprintCollection $blueprintCollection, Collection $collection, Filesystem $file, Repository $repository, Blueprint $blueprint)
 {
     $input = $request->get('collection');
     // Check if there's anything to remove
     if (isset($input['remove'])) {
         // Archive default storage path
         $buildcraftArchiveStoragePath = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.archives'));
         // get an array of ids to remove
         foreach ($input['remove'] as $key => $value) {
             $remove[] = $key;
         }
         // Remove the ids
         $blueprintCollection->destroy($remove);
         //Rebuild the archive
         // Get the current archive and delete it
         $currentArchive = $collection->where(['id' => $collectionId])->select('archive_name')->first()->toArray();
         if ($file->exists($buildcraftArchiveStoragePath . $currentArchive['archive_name'])) {
             $file->delete($buildcraftArchiveStoragePath . $currentArchive['archive_name']);
         }
         // Get the ids that are still there
         $rebuild = $blueprintCollection->where(['collection_id' => $collectionId])->select('blueprint_id')->get()->toArray();
         $filesToRearchive = $blueprint->select('archive_name')->whereIn('id', array_flatten($rebuild))->get()->toArray();
         // Create a random name for the collection archive
         $collectionArchiveName = str_replace(' ', '', $input['name']) . '_' . getRandomId() . '_collection' . '.zip';
         // Start creating the archive
         $zipper->make($buildcraftArchiveStoragePath . $collectionArchiveName);
         foreach ($filesToRearchive as $key => $value) {
             // Add each archive to the the newly created archive
             $zipper->add($buildcraftArchiveStoragePath . $value['archive_name']);
         }
         //Clean up
         $zipper->close();
         $input['archive_name'] = $collectionArchiveName;
     }
     // Don't bother checking if anything has changed
     // just update the whole thing
     $collection->find($collectionId)->update($input);
     // Send the user back
     return redirect()->back()->with('collectionUpdateSuccess', true);
 }