sfx2/source/doc/objstor.cxx |   41 +++++++++++++----------------------------
 1 file changed, 13 insertions(+), 28 deletions(-)

New commits:
commit 61c12dd1c80e4b7227a614227bb690b00feb78ad
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Jan 7 13:30:18 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Jan 7 12:26:38 2025 +0100

    tdf#164619: bite the bullet, and write the correct ODF version
    
    The problem was the inconsistency between ODF versions for the forms
    in the package and the form's content.xml. The check
    for consistency was introduced in version 5.4 in commit
    0a0f205775807d63e7f6dd910de368bb12b11a49 (tdf#105686 - fixed wrongly
    imported named expressions:, 2017-03-21). In version 7.0, commit
    9fdf8c0a5cc036ea9bd1e11dd8f2c1a6e601fae2 (Also consider saved
    exceptions when terminating parse, 2019-11-16) made the exception
    from that check fatal.
    
    Commit 519d96fd8b83ef4c61576d87b58f97b7e6e6e3c6 (tdf#134582 sfx2:
    when storing, set Version on embedded object storage, 2020-07-10)
    started to write the embedded object versions to package manifest,
    and commit 16de54a5c47fbc4691ee099c1f7bb559a8fe11ac (tdf#138209 ODF
    export: work around forms problem in LO < 7.0, 2021-05-10) created
    an exception for forms, to workaround the problem in older versions.
    But the latter commit created the reverse inconsistency, where the
    newer versions started to write older ODF version in manifest.xml,
    but newer ODF version in content.xml.
    
    This change restores the correct version written to the manifest.
    It is already messy in the already-released versions; it doesn't
    look possible to restore sanity retroactively, so just make it
    correct from now on, and accept the problem in older versions.
    
    Change-Id: If5d07b6000b9f08b33844db48b815881bed2915b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179867
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index aa1dc0c29070..9e1861285ac8 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -132,6 +132,17 @@ using namespace ::com::sun::star::document;
 using namespace ::cppu;
 
 
+static css::uno::Any getODFVersionAny(SvtSaveOptions::ODFSaneDefaultVersion v)
+{
+    if (v >= SvtSaveOptions::ODFSaneDefaultVersion::ODFSVER_014)
+        return css::uno::Any(ODFVER_014_TEXT);
+    else if (v >= SvtSaveOptions::ODFSaneDefaultVersion::ODFSVER_013)
+        return css::uno::Any(ODFVER_013_TEXT);
+    else
+        return css::uno::Any(ODFVER_012_TEXT);
+}
+
+
 void impl_addToModelCollection(const css::uno::Reference< css::frame::XModel 
>& xModel)
 {
     if (!xModel.is())
@@ -346,22 +357,7 @@ void SfxObjectShell::SetupStorage( const uno::Reference< 
embed::XStorage >& xSto
         try
         {
             // older versions can not have this property set, it exists only 
starting from ODF1.2
-            uno::Reference<frame::XModule> const xModule(GetModel(), 
uno::UNO_QUERY);
-            bool const isBaseForm(xModule.is() &&
-                xModule->getIdentifier() == "com.sun.star.sdb.FormDesign");
-            SAL_INFO_IF(isBaseForm, "sfx.doc", "tdf#138209 force form export 
to ODF 1.2");
-            if (!isBaseForm && SvtSaveOptions::ODFSVER_014 <= nDefVersion)
-            {
-                xProps->setPropertyValue(u"Version"_ustr, 
uno::Any(ODFVER_014_TEXT));
-            }
-            else if (!isBaseForm && SvtSaveOptions::ODFSVER_013 <= nDefVersion)
-            {
-                xProps->setPropertyValue(u"Version"_ustr, 
uno::Any(ODFVER_013_TEXT));
-            }
-            else
-            {
-                xProps->setPropertyValue(u"Version"_ustr, 
uno::Any(ODFVER_012_TEXT));
-            }
+            xProps->setPropertyValue(u"Version"_ustr, 
getODFVersionAny(nDefVersion));
         }
         catch( uno::Exception& )
         {
@@ -1330,18 +1326,7 @@ bool SfxObjectShell::DoSave()
             {
                 try // tdf#134582 set Version on embedded objects as they
                 {   // could have been loaded with a different/old version
-                    uno::Reference<frame::XModule> const xModule(GetModel(), 
uno::UNO_QUERY);
-                    bool const isBaseForm(xModule.is() &&
-                        xModule->getIdentifier() == 
"com.sun.star.sdb.FormDesign");
-                    SAL_INFO_IF(isBaseForm, "sfx.doc", "tdf#138209 force form 
export to ODF 1.2");
-                    if (!isBaseForm && SvtSaveOptions::ODFSVER_013 <= 
nDefVersion)
-                    {
-                        xProps->setPropertyValue(u"Version"_ustr, 
uno::Any(ODFVER_013_TEXT));
-                    }
-                    else
-                    {
-                        xProps->setPropertyValue(u"Version"_ustr, 
uno::Any(ODFVER_012_TEXT));
-                    }
+                    xProps->setPropertyValue(u"Version"_ustr, 
getODFVersionAny(nDefVersion));
                 }
                 catch (uno::Exception&)
                 {

Reply via email to