Code (PHP) pasted on 2019-08-05, 22:07 Raw Source
- <?php
- /**
- * the Import Module just iterates
- */
- use Aws\S3\S3Client;
- use League\Flysystem\AwsS3v3\AwsS3Adapter;
- use League\Flysystem\Cached\CachedAdapter;
- use League\Flysystem\Cached\Storage\Memory as MemoryStore;
- use League\Flysystem\Filesystem;
- $client = new S3Client($config['minio'][0]);
- $s3adapter = new AwsS3Adapter($client, 'photos', '', ['StorageClass' => 'REDUCED_REDUNDANCY']);
- $cacheStore = new MemoryStore();
- $adapter = new CachedAdapter($s3adapter, $cacheStore);
- $filesystem = new Filesystem($adapter);
- $contents = $filesystem->listContents('/', true);
- foreach ($contents as $object) {
- if ($object['type'] == "file") {
- $photoBean = R::findOne('photo', 'basename = ? AND path = ?', [$object['basename'], $object['path']]);
- $photoBean = R::dispense('photo');
- $photoBean->path = $object['path'];
- }
- $stream = $filesystem->readStream($object['path']);
- $content = "";
- $startFound = false;
- if ($offset != false) {
- $startFound = true;
- }
- }
- // jump to the found offset
- $endFound = false;
- if ($offset != false) {
- $endFound = true;
- }
- }
- $document = new DOMDocument();
- $document->loadXml($content);
- $xpath = new DOMXpath($document);
- /**
- * most likely a bit hackish.. thats how I do get all namespaces...
- */
- foreach ($matches[1] as $key => $alias) {
- // echo "registering $alias for ".$matches[2][$key]."\n";
- $xpath->registerNamespace($alias, $matches[2][$key]);
- }
- $elements = $xpath->query("//*[name()='dc:subject']//rdf:li");
- $tags = [];
- foreach ($elements as $element) {
- }
- }
- }
- $beanTags = R::tag($photoBean);
- // the bean has already tags connected to it.
- // add new tags
- foreach ($newTags as $tag) {
- R::addTags($photoBean, [$tag]);
- }
- }
- // and remove old tags
- foreach ($deleteTags as $tag) {
- R::untag($photoBean, [$tag]);
- }
- }
- // new bean - just add all tags.
- R::addTags($photoBean, $tags);
- } else {
- // old bean with tags attached though the pic does not have
- // any tags anymore. remove them
- foreach ($beanTags as $tag) {
- R::untag($photoBean, [$tag]);
- }
- }
- }
- // finally, store the bean and it's tags.
- R::store($photoBean);
- }
- }
- }