<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Hi Jacky,</p>
<p>I recommend to use PostgreSQL service names instead of hostname/port/db settings. The projects would connect the layers to a central pg_service.conf file that you can put on a network drive. On the day the db hostname changes, you can centrally switch the hostname/port/db in just a single text-file.</p>
<p>This also helps to switch between test/integration/production environments by simply pointing to a different pg_service.conf file (see Options --> System --> Environment and user defined variables. You can use either PGSERVICEFILE or PGSYSCONFDIR).</p>
<p>Seems to me easier and more flexible than what you have in mind with scripting and signals.</p>
<p>Greetings,</p>
<p>Andreas</p>
<p id="reply-intro">On 2020-11-26 16:06, VOLPES-EXT, Jacky wrote:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<div id="replybody1">
<style type="text/css">@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Segoe UI";
        panose-1:2 11 5 2 4 2 4 2 2 3;}
@font-face
        {font-family:"Segoe UI Semilight";
        panose-1:2 11 4 2 4 2 4 2 2 3;}

#replybody1 p.v1MsoNormal, #replybody1 li.v1MsoNormal, #replybody1 div.v1MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
#replybody1 a:link, #replybody1 span.v1MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
#replybody1 a:visited, #replybody1 span.v1MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
#replybody1 span.v1EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
#replybody1 span.v1EmailStyle18
        {mso-style-type:personal;}
#replybody1 span.v1EmailStyle19
        {mso-style-type:personal;}
#replybody1 .v1MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
#replybody1 div.v1WordSection1
        {page:WordSection1;}</style>
<div lang="FR">
<div class="v1WordSection1">
<p class="v1MsoNormal">Hello QGIS dev team <span style="font-family: Wingdings;">J</span></p>
<p class="v1MsoNormal"> </p>
<p class="v1MsoNormal"><span>I need to modify QGIS project file at reading (loading) time.</span></p>
<p class="v1MsoNormal"><span>The database hostname used in the company is changing soon, and I need this to be transparent for the users.</span></p>
<p class="v1MsoNormal"><span> </span></p>
<p class="v1MsoNormal"><span>The problem is that all their layers with the old database connections (uri) will trigger a connection error, having the old hostname.</span></p>
<p class="v1MsoNormal"><span>The idea is to update the .qgs file that is being opened with the new hostname with a text-replacement plugin, save the file, and eventually load it in QGIS.</span></p>
<p class="v1MsoNormal"><span>So that the user will not see any difference or error message.</span></p>
<p class="v1MsoNormal"><span> </span></p>
<p class="v1MsoNormal"><span>Sadly, the QgsProject.readLayer signal is sent after the project has been loaded, hence after the connection error messages…</span></p>
<p class="v1MsoNormal"><span> </span></p>
<p class="v1MsoNormal"><span>Any suggestion/idea welcome!</span></p>
<p class="v1MsoNormal"><span>Thanks,</span></p>
<p class="v1MsoNormal"><span> </span></p>
<p class="v1MsoNormal" style="margin-top: 5.0pt; page-break-after: avoid;"><strong><span style="font-size: 9.0pt; font-family: 'Segoe UI',sans-serif; color: #0054a5; mso-fareast-language: FR;">Jacky Volpes</span></strong><strong><span style="font-size: 10.5pt; font-family: 'Segoe UI',sans-serif; color: #0054a5; mso-fareast-language: FR;"> <br /></span></strong><span style="font-size: 8.0pt; font-family: 'Segoe UI Semilight',sans-serif; color: #595959; mso-fareast-language: FR;">Développeur python </span></p>
<p class="v1MsoNormal" style="margin-bottom: 5.0pt; page-break-after: avoid;"><span style="font-size: 8.0pt; font-family: 'Segoe UI Semilight',sans-serif; color: #595959; mso-fareast-language: FR;">HR-Team pour la Société du Canal de Provence<br />Direction des Systèmes d’Information<br /><br /></span><span style="font-size: 9.0pt; font-family: 'Segoe UI Semilight',sans-serif; color: #595959; mso-fareast-language: FR;">Tél.</span><span style="font-size: 9.0pt; font-family: 'Segoe UI',sans-serif; color: #595959; mso-fareast-language: FR;"> </span><strong><span style="font-size: 9.0pt; font-family: 'Segoe UI',sans-serif; color: #0054a5; mso-fareast-language: FR;">04 42 66 70 34</span></strong><span style="font-size: 9.0pt; font-family: 'Segoe UI Semilight',sans-serif; color: #595959; mso-fareast-language: FR;"><br />Le Tholonet - CS 70064 - 13182 Aix-en-Provence CEDEX 5</span><span style="font-size: 10.5pt; font-family: 'Segoe UI',sans-serif; color: #7f7f7f; mso-fareast-language: FR;"><br /></span><span style="mso-fareast-language: FR;"><img id="v1Image_x0020_1" src="cid:16064040205fbfc7b47d11d821625778@carto.net" alt="cid:image001.png@01D34C22.F8A861A0" width="314" height="96" /></span><span style="font-size: 8.0pt; font-family: 'Segoe UI Semilight',sans-serif; color: #595959; mso-fareast-language: FR;"></span></p>
<p class="v1MsoNormal"> </p>
</div>
</div>
</div>
<br />
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">_______________________________________________<br />QGIS-Developer mailing list<br /><a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><br />List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank" rel="noopener noreferrer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br />Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank" rel="noopener noreferrer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></div>
</blockquote>
<p><br /></p>

</body></html>