renamed ImageMetaData.CategoryId to CategoryPiwigoId -> Db rebuild required
This commit is contained in:
parent
b99e990747
commit
2a4a8e2e01
@ -36,13 +36,13 @@ type ImageMetaData struct {
|
||||
Md5Sum string
|
||||
LastChange time.Time
|
||||
CategoryPath string
|
||||
CategoryId int
|
||||
CategoryPiwigoId int
|
||||
UploadRequired bool
|
||||
DeleteRequired bool
|
||||
}
|
||||
|
||||
func (img *ImageMetaData) String() string {
|
||||
return fmt.Sprintf("ImageMetaData{ImageId:%d, PiwigoId:%d, CategoryId:%d, RelPath:%s, File:%s, Md5:%s, Change:%sS, catpath:%s, UploadRequired: %t, DeleteRequired: %t}", img.ImageId, img.PiwigoId, img.CategoryId, img.FullImagePath, img.Filename, img.Md5Sum, img.LastChange.String(), img.CategoryPath, img.UploadRequired, img.DeleteRequired)
|
||||
return fmt.Sprintf("ImageMetaData{ImageId:%d, PiwigoId:%d, CategoryPiwigoId:%d, RelPath:%s, File:%s, Md5:%s, Change:%sS, catpath:%s, UploadRequired: %t, DeleteRequired: %t}", img.ImageId, img.PiwigoId, img.CategoryPiwigoId, img.FullImagePath, img.Filename, img.Md5Sum, img.LastChange.String(), img.CategoryPath, img.UploadRequired, img.DeleteRequired)
|
||||
}
|
||||
|
||||
type CategoryProvider interface {
|
||||
@ -114,7 +114,7 @@ func (d *LocalDataStore) ImageMetadata(fullImagePath string) (ImageMetaData, err
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
stmt, err := db.Prepare("SELECT imageId, piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryId, uploadRequired, deleteRequired FROM image WHERE fullImagePath = ?")
|
||||
stmt, err := db.Prepare("SELECT imageId, piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryPiwigoId, uploadRequired, deleteRequired FROM image WHERE fullImagePath = ?")
|
||||
if err != nil {
|
||||
return img, err
|
||||
}
|
||||
@ -147,7 +147,7 @@ func (d *LocalDataStore) ImageMetadataAll() ([]ImageMetaData, error) {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
rows, err := db.Query("SELECT imageId, piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryId, uploadRequired, deleteRequired FROM image")
|
||||
rows, err := db.Query("SELECT imageId, piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryPiwigoId, uploadRequired, deleteRequired FROM image")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -176,7 +176,7 @@ func (d *LocalDataStore) ImageMetadataToDelete() ([]ImageMetaData, error) {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
rows, err := db.Query("SELECT imageId, piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryId, uploadRequired, deleteRequired FROM image WHERE deleteRequired = 1")
|
||||
rows, err := db.Query("SELECT imageId, piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryPiwigoId, uploadRequired, deleteRequired FROM image WHERE deleteRequired = 1")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -205,7 +205,7 @@ func (d *LocalDataStore) ImageMetadataToUpload() ([]ImageMetaData, error) {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
rows, err := db.Query("SELECT imageId, piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryId, uploadRequired, deleteRequired FROM image WHERE uploadRequired = 1 and deleteRequired = 0 order by fullImagePath asc")
|
||||
rows, err := db.Query("SELECT imageId, piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryPiwigoId, uploadRequired, deleteRequired FROM image WHERE uploadRequired = 1 and deleteRequired = 0 order by fullImagePath asc")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -226,7 +226,7 @@ func (d *LocalDataStore) ImageMetadataToUpload() ([]ImageMetaData, error) {
|
||||
}
|
||||
|
||||
func ReadImageMetadataFromRow(rows *sql.Rows, img *ImageMetaData) error {
|
||||
err := rows.Scan(&img.ImageId, &img.PiwigoId, &img.FullImagePath, &img.Filename, &img.Md5Sum, &img.LastChange, &img.CategoryPath, &img.CategoryId, &img.UploadRequired, &img.DeleteRequired)
|
||||
err := rows.Scan(&img.ImageId, &img.PiwigoId, &img.FullImagePath, &img.Filename, &img.Md5Sum, &img.LastChange, &img.CategoryPath, &img.CategoryPiwigoId, &img.UploadRequired, &img.DeleteRequired)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -331,11 +331,11 @@ func (d *LocalDataStore) DeleteMarkedImages() error {
|
||||
}
|
||||
|
||||
func (d *LocalDataStore) insertImageMetaData(tx *sql.Tx, data ImageMetaData) error {
|
||||
stmt, err := tx.Prepare("INSERT INTO image (piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryId, uploadRequired, deleteRequired) VALUES (?,?,?,?,?,?,?,?,?)")
|
||||
stmt, err := tx.Prepare("INSERT INTO image (piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryPiwigoId, uploadRequired, deleteRequired) VALUES (?,?,?,?,?,?,?,?,?)")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = stmt.Exec(data.PiwigoId, data.FullImagePath, data.Filename, data.Md5Sum, data.LastChange, data.CategoryPath, data.CategoryId, data.UploadRequired, data.DeleteRequired)
|
||||
_, err = stmt.Exec(data.PiwigoId, data.FullImagePath, data.Filename, data.Md5Sum, data.LastChange, data.CategoryPath, data.CategoryPiwigoId, data.UploadRequired, data.DeleteRequired)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -359,7 +359,7 @@ func (d *LocalDataStore) createTablesIfNeeded(db *sql.DB) error {
|
||||
"md5sum NVARCHAR(50) NOT NULL," +
|
||||
"lastChanged DATETIME NOT NULL," +
|
||||
"categoryPath NVARCHAR(1000) NOT NULL," +
|
||||
"categoryId INTEGER NULL," +
|
||||
"categoryPiwigoId INTEGER NULL," +
|
||||
"uploadRequired BIT NOT NULL," +
|
||||
"deleteRequired BIT NOT NULL" +
|
||||
");")
|
||||
@ -368,14 +368,29 @@ func (d *LocalDataStore) createTablesIfNeeded(db *sql.DB) error {
|
||||
}
|
||||
|
||||
_, err = db.Exec("CREATE UNIQUE INDEX IF NOT EXISTS UX_ImageFullImagePath ON image (fullImagePath);")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = db.Exec("CREATE TABLE IF NOT EXISTS category (" +
|
||||
"CategoryId INTEGER PRIMARY KEY," +
|
||||
"PiwigoId INTEGER NULL," +
|
||||
"PiwigoParentId INTEGER NULL," +
|
||||
"Name NVARCHAR(255) NOT NULL," +
|
||||
"Key NVARCHAR(1000) NOT NULL" +
|
||||
");")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *LocalDataStore) updateImageMetaData(tx *sql.Tx, data ImageMetaData) error {
|
||||
stmt, err := tx.Prepare("UPDATE image SET piwigoId = ?, fullImagePath = ?, fileName = ?, md5sum = ?, lastChanged = ?, categoryPath = ?, categoryId = ?, uploadRequired = ?, deleteRequired = ? WHERE imageId = ?")
|
||||
stmt, err := tx.Prepare("UPDATE image SET piwigoId = ?, fullImagePath = ?, fileName = ?, md5sum = ?, lastChanged = ?, categoryPath = ?, categoryPiwigoId = ?, uploadRequired = ?, deleteRequired = ? WHERE imageId = ?")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = stmt.Exec(data.PiwigoId, data.FullImagePath, data.Filename, data.Md5Sum, data.LastChange, data.CategoryPath, data.CategoryId, data.UploadRequired, data.DeleteRequired, data.ImageId)
|
||||
_, err = stmt.Exec(data.PiwigoId, data.FullImagePath, data.Filename, data.Md5Sum, data.LastChange, data.CategoryPath, data.CategoryPiwigoId, data.UploadRequired, data.DeleteRequired, data.ImageId)
|
||||
return err
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ func getExampleImageMetadata(filePath string) ImageMetaData {
|
||||
LastChange: time.Now().UTC(),
|
||||
Filename: "bar.jpg",
|
||||
CategoryPath: "blah/foo",
|
||||
CategoryId: 100,
|
||||
CategoryPiwigoId: 100,
|
||||
UploadRequired: true,
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func synchronizeLocalImageMetadataScanNewFiles(fileSystemNodes map[string]*local
|
||||
|
||||
category, err := categoryDb.GetCategoryByKey(metadata.CategoryPath)
|
||||
if err == nil {
|
||||
metadata.CategoryId = category.PiwigoId
|
||||
metadata.CategoryPiwigoId = category.PiwigoId
|
||||
} else {
|
||||
logrus.Warnf("No category found for image %s - %s", file.Path, err)
|
||||
}
|
||||
@ -129,7 +129,7 @@ func UploadImages(piwigoCtx piwigo.PiwigoImageApi, metadataProvider datastore.Im
|
||||
|
||||
for _, img := range images {
|
||||
|
||||
imgId, err := piwigoCtx.UploadImage(img.PiwigoId, img.FullImagePath, img.Md5Sum, img.CategoryId)
|
||||
imgId, err := piwigoCtx.UploadImage(img.PiwigoId, img.FullImagePath, img.Md5Sum, img.CategoryPiwigoId)
|
||||
if err != nil {
|
||||
logrus.Warnf("could not upload image %s. Continuing with the next image.", img.FullImagePath)
|
||||
continue
|
||||
|
@ -56,7 +56,7 @@ func Test_synchronize_local_image_metadata_should_add_new_metadata(t *testing.T)
|
||||
fileSystemNodes[testFileSystemNode.Key] = testFileSystemNode
|
||||
|
||||
image := createImageMetaDataFromFilesystem(testFileSystemNode, 0, true, false)
|
||||
image.CategoryId = category.PiwigoId
|
||||
image.CategoryPiwigoId = category.PiwigoId
|
||||
image.CategoryPath = category.Key
|
||||
|
||||
db := NewMockImageMetadataProvider(mockCtrl)
|
||||
@ -541,7 +541,7 @@ func createTestImageMetaData(piwigoId int) datastore.ImageMetaData {
|
||||
FullImagePath: "/nonexisting/file.jpg",
|
||||
UploadRequired: true,
|
||||
Md5Sum: "1234",
|
||||
CategoryId: 2,
|
||||
CategoryPiwigoId: 2,
|
||||
}
|
||||
return img
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user