Ejemplo n.º 1
0
def map_album(old_obj, album):
    plone_uid = old_obj.UID()
    album.plone_uid = plone_uid
    album.idcategoria = 1
    album.titulo = old_obj.Title().decode('utf-8').encode(
        'iso8859-1', 'ignore')
    album.thumb = 0
    album.dataevento = int(old_obj.created().timeTime())
    album.dataexpiracao = 0
    album.descricao = old_obj.Description().decode('utf-8').encode(
        'iso8859-1', 'ignore')
    album.publicado = 1
    album.plone_path = '/'.join(old_obj.getPhysicalPath()[3:])
    session = db.get().Session()
    session.flush()
    album.diretorio = album.idevento
    create_album_directory(album.idevento)
    for old_photo in old_obj.objectValues():
        if old_photo.portal_type != 'ATPhoto':
            continue
        photo = session.query(
            db.NewPhoto).filter_by(plone_uid=old_photo.UID()).first()
        if photo is None:
            photo = db.NewPhoto()
            session.add(photo)
        map_photo(old_photo, photo, album.idevento, old_obj)
Ejemplo n.º 2
0
def migrate_content(context, portal_type, mapper, map_func, debug=False):
    """Migrate portal_type content from Plone to SQLDatabase, using map_content function
    context: Plone Site object
    """
    results = query_catalog(context, portal_type)
    conn = db.get()
    session = conn.Session()
    debug_text = 'Begin Import: %s - %s %s' % (portal_type, str(
        DateTime()), '\n')
    for item in results:
        old_obj = item.getObject()
        UID = old_obj.UID()
        new_obj = session.query(mapper).filter_by(plone_uid=UID).first()
        if new_obj is None:
            new_obj = mapper()
            session.add(new_obj)
        new_obj = map_func(old_obj, new_obj)
        if debug is True:
            debug_text += old_obj.Title() + ' | ' \
            + str(old_obj.created()) + ' | ' \
            + '/'.join(old_obj.getPhysicalPath()[3:]) + '\n'

    debug_text += 'End Import: %s - %s %s' % (portal_type, str(
        DateTime()), '\n')
    print debug_text
    return debug_text
Ejemplo n.º 3
0
def create_news_relations(old_obj, noticia, reverse=False):
    conn = db.get()
    session = conn.Session()
    session.flush()
    noticia_sqlid = noticia.storyid
    noticia_uid = old_obj.UID()

    for item in old_obj.getRelatedItems():
        related_desc = map_type.get(item.portal_type)
        related_uid = item.UID()
        if related_desc == 'galeria':
            field_sqlid = 'idevento'
            related_type = db.NewAlbum
        elif related_desc == 'noticias':
            field_sqlid = 'storyid'
            related_type = db.NewNoticia
        else:
            field_sqlid = 'xfid'
            related_type = db.NewMedia

        related = session.query(related_type).filter_by(
            plone_uid=related_uid).first()
        if related is None:
            continue
        related_sqlid = getattr(related, field_sqlid)

        relation_direct = session.query(
            db.NewRelation).filter_by(content_plone_uid=noticia_uid,
                                      related_plone_uid=related_uid).first()
        if relation_direct is None:
            relation_direct = db.NewRelation()
            session.add(relation_direct)
        relation_direct.idcontend = noticia_sqlid
        relation_direct.modulecontend = 'noticias'
        relation_direct.idrelated = related_sqlid
        relation_direct.modulerelated = related_desc
        relation_direct.content_plone_uid = noticia_uid
        relation_direct.related_plone_uid = related_uid

        if reverse is True:
            relation_reverse = session.query(db.NewRelation).filter_by(
                content_plone_uid=related_uid,
                related_plone_uid=noticia_uid).first()
            if relation_reverse is None:
                relation_reverse = db.NewRelation()
                session.add(relation_reverse)
            relation_reverse.idcontend = related_sqlid
            relation_reverse.modulecontend = related_desc
            relation_reverse.idrelated = noticia_sqlid
            relation_reverse.modulerelated = 'noticias'
            relation_reverse.content_plone_uid = related_uid
            relation_reverse.related_plone_uid = noticia_uid
Ejemplo n.º 4
0
def create_news_relations(old_obj, noticia, reverse=False):
    conn = db.get()
    session = conn.Session()
    session.flush()
    noticia_sqlid = noticia.storyid
    noticia_uid = old_obj.UID()

    for item in old_obj.getRelatedItems():
        related_desc = map_type.get(item.portal_type)
        related_uid = item.UID()
        if related_desc == 'galeria':
            field_sqlid = 'idevento'
            related_type = db.NewAlbum
        elif related_desc == 'noticias':
            field_sqlid = 'storyid'
            related_type = db.NewNoticia
        else:
            field_sqlid = 'xfid'
            related_type = db.NewMedia

        related = session.query(related_type).filter_by(plone_uid=related_uid).first()
        if related is None:
            continue
        related_sqlid = getattr(related, field_sqlid)

        relation_direct = session.query(db.NewRelation).filter_by(
                content_plone_uid=noticia_uid,
                related_plone_uid=related_uid).first()
        if relation_direct is None:
            relation_direct = db.NewRelation()
            session.add(relation_direct)
        relation_direct.idcontend = noticia_sqlid
        relation_direct.modulecontend = 'noticias'
        relation_direct.idrelated = related_sqlid
        relation_direct.modulerelated = related_desc
        relation_direct.content_plone_uid = noticia_uid
        relation_direct.related_plone_uid = related_uid

        if reverse is True:
            relation_reverse = session.query(db.NewRelation).filter_by(
                    content_plone_uid=related_uid,
                    related_plone_uid=noticia_uid).first()
            if relation_reverse is None:
                relation_reverse = db.NewRelation()
                session.add(relation_reverse)
            relation_reverse.idcontend = related_sqlid
            relation_reverse.modulecontend = related_desc
            relation_reverse.idrelated = noticia_sqlid
            relation_reverse.modulerelated = 'noticias'
            relation_reverse.content_plone_uid = related_uid
            relation_reverse.related_plone_uid = noticia_uid
Ejemplo n.º 5
0
def map_album(old_obj, album):
    plone_uid = old_obj.UID()
    album.plone_uid = plone_uid
    album.idcategoria = 1
    album.titulo = old_obj.Title().decode('utf-8').encode('iso8859-1','ignore')
    album.thumb = 0
    album.dataevento = int(old_obj.created().timeTime())
    album.dataexpiracao = 0
    album.descricao = old_obj.Description().decode('utf-8').encode('iso8859-1','ignore')
    album.publicado = 1
    album.plone_path = '/'.join(old_obj.getPhysicalPath()[3:])
    session = db.get().Session()
    session.flush()
    album.diretorio = album.idevento
    create_album_directory(album.idevento)
    for old_photo in old_obj.objectValues():
        if old_photo.portal_type != 'ATPhoto':
            continue
        photo = session.query(db.NewPhoto).filter_by(plone_uid=old_photo.UID()).first()
        if photo is None:
            photo = db.NewPhoto()
            session.add(photo)
        map_photo(old_photo, photo, album.idevento, old_obj)
Ejemplo n.º 6
0
def migrate_content(context, portal_type, mapper, map_func, debug=False):
    """Migrate portal_type content from Plone to SQLDatabase, using map_content function
    context: Plone Site object
    """
    results = query_catalog(context, portal_type)
    conn = db.get()
    session = conn.Session()
    debug_text = 'Begin Import: %s - %s %s' % (portal_type ,str(DateTime()),'\n')
    for item in results:
        old_obj = item.getObject()
        UID = old_obj.UID()
        new_obj = session.query(mapper).filter_by(plone_uid=UID).first()
        if new_obj is None:
            new_obj = mapper()
            session.add(new_obj)
        new_obj = map_func(old_obj, new_obj)
        if debug is True:
            debug_text += old_obj.Title() + ' | ' \
            + str(old_obj.created()) + ' | ' \
            + '/'.join(old_obj.getPhysicalPath()[3:]) + '\n'

    debug_text += 'End Import: %s - %s %s' % (portal_type, str(DateTime()), '\n')
    print debug_text
    return debug_text