A partir de la version 1.6.x, le prix de l'annonce a été ajouté au modèle des petites annonces: attribut "price" de type double.
Si vous aviez déjà surchargé le type des petites annonce pour ajouter le prix "price" :
Supprimez la déclaration de "price" dans votre surcharge
Si le type de votre "price" était un string au lieu de double, exécutez le script suivant pour migrer l'attribut "price" de string à double pour vos annonces existantes. Passer handle à true pour rendre le script effectif.
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
let handle = false;
let success = 0;
let failure = 0;
let logger = Ametys.getLogger("org.ametys.plugins.classifiedads.migrate.price", { "filename": "migration", "level": "info" });
Repository.query("//element(*, ametys:content)[@ametys-internal:contentType = 'org.ametys.plugins.classified.ads.Content.ads']").forEach(
content =>
{
if (handle)
{
Content.migrate(
content,
[_migratePrice],
false /* old versions are still compatible */,
null /* no tag */,
false /* not verbose */,
true /* Synchronize with live workspace */
);
}
else
{
_migratePrice(content);
}
}
);
logger.info(`${success} ads have been migrated`);
if (failure > 0)
{
logger.warn(`Migration of ${failure} ads failed`);
}
function _migratePrice(content)
{
if (content.getNode().hasProperty("ametys:price"))
{
if (content.getNode().getProperty("ametys:price").getType() == 1)
{
let val = content.getNode().getProperty("ametys:price").getString();
let asDouble = parseFloat(val.replaceAll(",", "."));
if (Number.isNaN(asDouble))
{
logger.warn(`Price "${val}" can not be parse to double for content ${content.getTitle()} (${content.getId()})`);
failure++;
}
else
{
logger.debug(`Price "${val}" migrated to "${asDouble}" on content ${content.getTitle()} (${content.getId()})`);
if (handle)
{
content.getNode().getProperty("ametys:price").remove();
content.setValue("price", asDouble);
}
success++;
}
}
}
}
let handle = false;
let success = 0;
let failure = 0;
let logger = Ametys.getLogger("org.ametys.plugins.classifiedads.migrate.price", { "filename": "migration", "level": "info" });
Repository.query("//element(*, ametys:content)[@ametys-internal:contentType = 'org.ametys.plugins.classified.ads.Content.ads']").forEach(
content =>
{
if (handle)
{
Content.migrate(
content,
[_migratePrice],
false /* old versions are still compatible */,
null /* no tag */,
false /* not verbose */,
true /* Synchronize with live workspace */
);
}
else
{
_migratePrice(content);
}
}
);
logger.info(`${success} ads have been migrated`);
if (failure > 0)
{
logger.warn(`Migration of ${failure} ads failed`);
}
function _migratePrice(content)
{
if (content.getNode().hasProperty("ametys:price"))
{
if (content.getNode().getProperty("ametys:price").getType() == 1)
{
let val = content.getNode().getProperty("ametys:price").getString();
let asDouble = parseFloat(val.replaceAll(",", "."));
if (Number.isNaN(asDouble))
{
logger.warn(`Price "${val}" can not be parse to double for content ${content.getTitle()} (${content.getId()})`);
failure++;
}
else
{
logger.debug(`Price "${val}" migrated to "${asDouble}" on content ${content.getTitle()} (${content.getId()})`);
if (handle)
{
content.getNode().getProperty("ametys:price").remove();
content.setValue("price", asDouble);
}
success++;
}
}
}
}
let handle = false;
let success = 0;
let failure = 0;
let logger = Ametys.getLogger("org.ametys.plugins.classifiedads.migrate.price", { "filename": "migration", "level": "info" });
Repository.query("//element(*, ametys:content)[@ametys-internal:contentType = 'org.ametys.plugins.classified.ads.Content.ads']").forEach(
content =>
{
if (handle)
{
Content.migrate(
content,
[_migratePrice],
false /* old versions are still compatible */,
null /* no tag */,
false /* not verbose */,
true /* Synchronize with live workspace */
);
}
else
{
_migratePrice(content);
}
}
);
logger.info(`${success} ads have been migrated`);
if (failure > 0)
{
logger.warn(`Migration of ${failure} ads failed`);
}
function _migratePrice(content)
{
if (content.getNode().hasProperty("ametys:price"))
{
if (content.getNode().getProperty("ametys:price").getType() == 1)
{
let val = content.getNode().getProperty("ametys:price").getString();
let asDouble = parseFloat(val.replaceAll(",", "."));
if (Number.isNaN(asDouble))
{
logger.warn(`Price "${val}" can not be parse to double for content ${content.getTitle()} (${content.getId()})`);
failure++;
}
else
{
logger.debug(`Price "${val}" migrated to "${asDouble}" on content ${content.getTitle()} (${content.getId()})`);
if (handle)
{
content.getNode().getProperty("ametys:price").remove();
content.setValue("price", asDouble);
}
success++;
}
}
}
}