server/migractions.py
brancholdstable
changeset 7254 c0278ad81823
parent 7116 dfd4680a23f0
child 7161 e3f69df8dac7
equal deleted inserted replaced
7178:a62f24e1497e 7254:c0278ad81823
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
  1305             self.commit()
  1305             self.commit()
  1306 
  1306 
  1307     # CWProperty handling ######################################################
  1307     # CWProperty handling ######################################################
  1308 
  1308 
  1309     def cmd_property_value(self, pkey):
  1309     def cmd_property_value(self, pkey):
  1310         rql = 'Any V WHERE X is CWProperty, X pkey %(k)s, X value V'
  1310         """retreive the site-wide persistent property value for the given key.
  1311         rset = self.rqlexec(rql, {'k': pkey}, ask_confirm=False)
  1311 
       
  1312         To get a user specific property value, use appropriate method on CWUser
       
  1313         instance.
       
  1314         """
       
  1315         rset = self.rqlexec(
       
  1316             'Any V WHERE X is CWProperty, X pkey %(k)s, X value V, NOT X for_user U',
       
  1317             {'k': pkey}, ask_confirm=False)
  1312         return rset[0][0]
  1318         return rset[0][0]
  1313 
  1319 
  1314     def cmd_set_property(self, pkey, value):
  1320     def cmd_set_property(self, pkey, value):
       
  1321         """set the site-wide persistent property value for the given key to the
       
  1322         given value.
       
  1323 
       
  1324         To set a user specific property value, use appropriate method on CWUser
       
  1325         instance.
       
  1326         """
  1315         value = unicode(value)
  1327         value = unicode(value)
  1316         try:
  1328         try:
  1317             prop = self.rqlexec('CWProperty X WHERE X pkey %(k)s', {'k': pkey},
  1329             prop = self.rqlexec(
  1318                                 ask_confirm=False).get_entity(0, 0)
  1330                 'CWProperty X WHERE X pkey %(k)s, NOT X for_user U',
       
  1331                 {'k': pkey}, ask_confirm=False).get_entity(0, 0)
  1319         except:
  1332         except:
  1320             self.cmd_create_entity('CWProperty', pkey=unicode(pkey), value=value)
  1333             self.cmd_create_entity('CWProperty', pkey=unicode(pkey), value=value)
  1321         else:
  1334         else:
  1322             self.rqlexec('SET X value %(v)s WHERE X pkey %(k)s',
  1335             prop.set_attributes(value=value)
  1323                          {'k': pkey, 'v': value}, ask_confirm=False)
       
  1324 
  1336 
  1325     # other data migration commands ###########################################
  1337     # other data migration commands ###########################################
  1326 
  1338 
  1327     @property
  1339     @property
  1328     def _cw(self):
  1340     def _cw(self):
  1357         """add a new entity of the given type"""
  1369         """add a new entity of the given type"""
  1358         entity = self._cw.create_entity(etype, **kwargs)
  1370         entity = self._cw.create_entity(etype, **kwargs)
  1359         if commit:
  1371         if commit:
  1360             self.commit()
  1372             self.commit()
  1361         return entity
  1373         return entity
       
  1374 
       
  1375     def cmd_find_entities(self, etype, **kwargs):
       
  1376         """find entities of the given type and attribute values"""
       
  1377         return self._cw.find_entities(etype, **kwargs)
       
  1378 
       
  1379     def cmd_find_one_entity(self, etype, **kwargs):
       
  1380         """find one entity of the given type and attribute values.
       
  1381 
       
  1382         raise :exc:`cubicweb.req.FindEntityError` if can not return one and only
       
  1383         one entity.
       
  1384         """
       
  1385         return self._cw.find_one_entity(etype, **kwargs)
  1362 
  1386 
  1363     def cmd_update_etype_fti_weight(self, etype, weight):
  1387     def cmd_update_etype_fti_weight(self, etype, weight):
  1364         if self.repo.system_source.dbdriver == 'postgres':
  1388         if self.repo.system_source.dbdriver == 'postgres':
  1365             self.sqlexec('UPDATE appears SET weight=%(weight)s '
  1389             self.sqlexec('UPDATE appears SET weight=%(weight)s '
  1366                          'FROM entities as X '
  1390                          'FROM entities as X '