diff options
4 files changed, 85 insertions, 0 deletions
diff --git a/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp new file mode 100644 index 0000000..1f99ce2 --- /dev/null +++ b/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp @@ -0,0 +1,52 @@ +#include "packageMetaProcessor.h" +#include <modifycommand.h> +#include "fileUtils.h" +#include "xmlUtils.h" +#include "dbUtils.h" +#include <sql/maintenance/packageMetaUpdate.sql.h> + +namespace U = Gentoo::Utils; +using namespace Gentoo::Utils::File; + +namespace Gentoo { + namespace Service { + const int PackageMetaProcessor::FILETYPEID = 4; + + void + PackageMetaProcessor::created(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const + { + update(dbc, fn, path); + } + + void + PackageMetaProcessor::update(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const + { + auto m = dbc->modify(sql::maintenance::packageMetaUpdate::sql); + U::XmlDoc md(path); + U::Database::bindOptionalsS(m, 0, { + md.getXPathValue("/pkgmetadata/longdescription[@lang='en']/text()"), + md.getXPathValue("/pkgmetadata/longdescription[1]/text()") + }); + m->bindParamS(1, (fn / 1).string()); + m->bindParamS(2, (fn / 2).string()); + m->execute(); + } + + void + PackageMetaProcessor::modified(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const + { + update(dbc, fn, path); + } + + void + PackageMetaProcessor::deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const + { + auto m = dbc->modify(sql::maintenance::packageMetaUpdate::sql); + m->bindNull(0); + m->bindParamS(1, (fn / 1).string()); + m->bindParamS(2, (fn / 2).string()); + m->execute(); + } + } +} + diff --git a/gentoobrowse-api/service/maintenance/packageMetaProcessor.h b/gentoobrowse-api/service/maintenance/packageMetaProcessor.h new file mode 100644 index 0000000..fb5ffa7 --- /dev/null +++ b/gentoobrowse-api/service/maintenance/packageMetaProcessor.h @@ -0,0 +1,25 @@ +#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_PACKAGEMETAPROC_H +#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_PACKAGEMETAPROC_H + +#include "../maintenanceimpl.h" +#include <connection.h> +#include <boost/filesystem/path.hpp> + +namespace Gentoo { + namespace Service { + class PackageMetaProcessor : public Maintenance::FileProcessor { + public: + static const int FILETYPEID; + + void created(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const; + void modified(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const; + void deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const; + + private: + void update(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const; + }; + } +} + +#endif + diff --git a/gentoobrowse-api/service/maintenanceimpl.cpp b/gentoobrowse-api/service/maintenanceimpl.cpp index d8b85ef..b81d959 100644 --- a/gentoobrowse-api/service/maintenanceimpl.cpp +++ b/gentoobrowse-api/service/maintenanceimpl.cpp @@ -8,6 +8,7 @@ #include <sql/maintenance/createTempFileListView.sql.h> #include "maintenance/categoryMetaProcessor.h" #include "maintenance/packageManifestProcessor.h" +#include "maintenance/packageMetaProcessor.h" /* 1 package metadata {"(1,metadata)","(2,md5-cache)"} @@ -49,6 +50,7 @@ namespace Gentoo { { fps[CategoryMetaProcessor::FILETYPEID] = new CategoryMetaProcessor(); fps[PackageManifestProcessor::FILETYPEID] = new PackageManifestProcessor(); + fps[PackageMetaProcessor::FILETYPEID] = new PackageMetaProcessor(); } Maintenance::~Maintenance() diff --git a/gentoobrowse-api/service/sql/maintenance/packageMetaUpdate.sql b/gentoobrowse-api/service/sql/maintenance/packageMetaUpdate.sql new file mode 100644 index 0000000..ec83634 --- /dev/null +++ b/gentoobrowse-api/service/sql/maintenance/packageMetaUpdate.sql @@ -0,0 +1,6 @@ +UPDATE gentoobrowse.packages p + SET summary = gentoobrowse.textclean(?) +FROM gentoobrowse.categories c +WHERE p.categoryid = c.categoryid +AND c.name = ? +AND p.name = ? |