HasContents attribute of Image objects after migration
If I'm correct, the HasContents attribute was introduced in Mendix version 2.5. We have migrated a 2.4 application with a lot of images and I'm not confident that all the images are available in the new application. The main reason for this is the following SQL statement being executed as part of the migration database changes: UPDATE [system$filedocument] SET [hascontents] = 1 WHERE NOT [name] IS NULL; Is it possible that there are images present in the UploadedFilesPath location that have a NULL value for the Name attribute? After all, in version 2.4 the Document/Name attribute wasn't required, right? The migration copies the old Document/Name attribute to the new FileDocument/Name attribute: UPDATE [system$filedocument] SET [name] = (SELECT [deleted_system$document].[name] FROM [deleted_system$document] WHERE [deleted_system$document].[id] = [system$filedocument].[id]) WHERE [id] IN (SELECT [deleted_system$document].[id] FROM [deleted_system$document]); If that is the case, the HasContents attribute doesn't properly reflect the fact that an actual file is present on the filesystem.
Jonathan van Alteren
I've managed to solve this issue myself. My assumption that the database migration script incorrectly sets HasContents to FALSE is true (we've tested this).
For those interested, I've written the following Python script to generate a usable SQL script to fix the issue:
mycount = 0
if os.path.exists(basepath) and os.path.isdir(basepath):
files = os.listdir(basepath)
for f in files:
print "count: %i" % mycount
print "Basepath '%s' does not exist or is not a directory" % basepath
def listMxFiles(basepath, file):
filepath = basepath + os.sep + file
print "update system$filedocument set hascontents = 1 where id = %s;" % file
mycount = mycount + 1
files = os.listdir(filepath)
for f in files:
print "Usage: fixHasContents.py <data files basepath>"
if __name__ == "__main__":
if len(sys.argv) > 1:
basepath = os.path.realpath(sys.argv)
print "Reading Mendix data files from basepath: %s" % basepath