zoukankan      html  css  js  c++  java
  • Openerp 7.0 附件存储位置

            我们知道对OpenERP中的每个内部对象(比如:业务伙伴,采购订单,销售订单,发货单,等等)我们都可以添加任意的附件,如图片,文档,视频等。那么这些附件在OpenERP内部是如何管理的呢?
            默认情况下,这些附件在OpenERP v7中是保存在数据库中的。我们知道当附件的数量比较大时,这会严重影响数据库的性能。其实在OpenERP 中我们可以通过设置ir.config.parameter参数来使附件保存在文件系统中,具体菜单位置是:
        ”设置-技术-参数-系统参数-ir_attachement.location” (Settings->Technical->Parameters-System parameters- ir_attachment.location)
    比如我们将
        ir_attachment.location
    设置为
        file:///filestore
    
    那么这些附件就会保存在
        openerp根目录/filestore下了, 系统使用sha1哈希算法来创建文件名所以重复的文件在系统中并不会多占空间。
    目前只支持
    
        file:/// 协议,实际上我们可以很容易通过扩增模块来支持;比如:amazons3:///协议,这样我们就可以将附件保存在亚马逊的S3云服务了。
    
    
    数据库保存附件的模式下,数据是保存在
        ir_attachment.db_datas;中
    文件系统保存附件的模式下,文件名保存在
        ir_attachment.db_datas_fname中;
    
            我们尚未能提供这两种模式的自动转换机制。所以,如果你设置了这个参数,那么已存在的附件仍将保存在数据库中,只有新附件会保存在文件系统中,系统会尝试访问这两个不同的位置,所以也没什么问题(先检查db_datas,然后再检查db_datas_fname)
            注:本文末尾提供的脚本可以自动将现有数据库中的附件转换到文件系统中
    如果你移除了这个参数,你需要设法将在文件系统中保存的附件存回到数据库中,因为系统就只会通过数据库来检查附件了。
    将现有数据库中的附件数据转移到文件系统中的脚本(替换URL为您的OpenERP实际访问URL地址):
    
    
    01	#!/usr/bin/python
    02	import xmlrpclib
    03	username = 'admin' #the user
    04	pwd = 'password'      #the password of the user
    05	dbname = 'database'    #the database
    06	 # Get the uid
    07	sock_common = xmlrpclib.ServerProxy ('<URL>/xmlrpc/common')
    08	uid = sock_common.login(dbname, username, pwd)
    09	sock = xmlrpclib.ServerProxy('<URL>/xmlrpc/object')
    10	def migrate_attachment(att_id):
    11	    # 1. get data
    12	    att = sock.execute(dbname, uid, pwd, 'ir.attachment', 'read', att_id, ['datas'])
    13	    data = att['datas']
    14	    # Re-Write attachment
    15	    a = sock.execute(dbname, uid, pwd, 'ir.attachment', 'write', [att_id], {'datas': data})
    16	# SELECT attachments:
    17	att_ids = sock.execute(dbname, uid, pwd, 'ir.attachment', 'search', [('store_fname','=',False)])
    18	cnt = len(att_ids)
    19	i = 0
    20	for id in att_ids:
    21	    att = sock.execute(dbname, uid, pwd, 'ir.attachment', 'read', id, ['datas','parent_id'])
    22	    migrate_attachment(id)
    23	    print 'Migrated ID %d (attachment %d of %d)' % (id,i,cnt)
    24	    i = i + 1
    25	print "done ..."
    
    
    运行这个脚本后,我们还需要清除ir_attachements表:
    
    
    1	update ir_attachment set db_datas = null where store_fname is not null
    2	vacuum (full, analyze) ir_attachment
    
  • 相关阅读:
    cmd输出的日志里有中文乱码的解决办法
    自定义控件ToggleButton滑动开关
    移除指定位置的jsonarray
    设置Listview不滚动
    Volley框架学习
    LoaderManager的使用
    Activity获取Fragment的值
    Fragment和Fragment进行数据传递
    Fragmet的学习
    android ListView上拉加载更多
  • 原文地址:https://www.cnblogs.com/chjbbs/p/3761544.html
Copyright © 2011-2022 走看看