public function store(Photo $photo) { $db = new PDO('sqlite:' . $this->dbPath); $db->setAttribute(\PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->exec('CREATE TABLE IF NOT EXISTS photos ( digikamId INTEGER PRIMARY KEY, googleId TEXT, googleUrl TEXT, currentRevision TEXT )'); $sql = 'REPLACE INTO photos ( digikamId, googleId, googleUrl, currentRevision ) VALUES ( :digikamId, :googleId, :googleUrl, :currentRevision )'; $statement = $db->prepare($sql); $id = $photo->getId(); $statement->bindParam(':digikamId', $id, PDO::PARAM_INT); $gid = $photo->getGoogleId(); $statement->bindParam(':googleId', $gid, PDO::PARAM_STR); $val = $photo->getGoogleUrl(); $statement->bindParam(':googleUrl', $val, PDO::PARAM_STR); $val = $photo->getCurrentRevision(); $statement->bindParam(':currentRevision', $val, PDO::PARAM_STR); $result = $statement->execute(); if (!$result) { throw new \Exception('REPLACE statement returned false'); } }
public function getPhotos() : PhotoCollection { $collection = new PhotoCollection(); $data = $this->getData(); $photo = null; foreach ($data as $current) { if ($current instanceof \stdClass) { /** @var \stdClass $current */ if ($photo instanceof Photo) { if ($photo->getId() == $current->id) { $photo->addTag(implode('/', [$current->tag1, $current->tag2, $current->tag3])); } else { $photo = Photo::createFromObject($current); } } else { $photo = Photo::createFromObject($current); } } elseif (is_array($current)) { /** @var array $current */ if ($photo instanceof Photo) { if ($photo->getId() == $current['id']) { $photo->addTag(implode('/', [$current['tag1'], $current['tag2'], $current['tag3']])); } else { $photo = Photo::createFromArray($current); } } else { $photo = Photo::createFromArray($current); } } $collection->add($photo); } return $collection; }
public function add(Photo $photo) : Google_Service_Drive_DriveFile { $googleId = $this->folderConfig->getGoogleId($photo->getSpecificPath() . $photo->getRelativePath()); if ($googleId === '') { $googleId = $this->folderConfig->getGoogleId($photo->getSpecificPath()); if ($googleId === '') { throw new \Exception(sprintf("Invalid configuration. DigiKam Drive Root Folder must be set. Folder Info given was %s \n", $photo->getSpecificPath())); } $googleId = $this->drive->createFolderStructure($googleId, $photo->getRelativePath()); $this->folderConfig->add($photo->getSpecificPath() . $photo->getRelativePath(), $googleId); } return $this->drive->add($photo, $googleId); }