331 def _create_context(self): |
331 def _create_context(self): |
332 """return a dictionary to use as migration script execution context""" |
332 """return a dictionary to use as migration script execution context""" |
333 context = super(ServerMigrationHelper, self)._create_context() |
333 context = super(ServerMigrationHelper, self)._create_context() |
334 context.update({'commit': self.checkpoint, |
334 context.update({'commit': self.checkpoint, |
335 'rollback': self.rollback, |
335 'rollback': self.rollback, |
336 'checkpoint': deprecated('[3.6] use commit')(self.checkpoint), |
|
337 'sql': self.sqlexec, |
336 'sql': self.sqlexec, |
338 'rql': self.rqlexec, |
337 'rql': self.rqlexec, |
339 'rqliter': self.rqliter, |
338 'rqliter': self.rqliter, |
340 'schema': self.repo.get_schema(), |
339 'schema': self.repo.get_schema(), |
341 'cnx': self.cnx, |
340 'cnx': self.cnx, |
342 'fsschema': self.fs_schema, |
341 'fsschema': self.fs_schema, |
343 'session' : self.session, |
342 'session' : self.session, |
344 'repo' : self.repo, |
343 'repo' : self.repo, |
345 'synchronize_schema': deprecated()(self.cmd_sync_schema_props_perms), # 3.4 |
|
346 'synchronize_eschema': deprecated()(self.cmd_sync_schema_props_perms), # 3.4 |
|
347 'synchronize_rschema': deprecated()(self.cmd_sync_schema_props_perms), # 3.4 |
|
348 }) |
344 }) |
349 return context |
345 return context |
350 |
346 |
351 @cached |
347 @cached |
352 def group_mapping(self): |
348 def group_mapping(self): |
395 driver = self.repo.system_source.dbdriver |
391 driver = self.repo.system_source.dbdriver |
396 if cube is None: |
392 if cube is None: |
397 directory = osp.join(CW_SOFTWARE_ROOT, 'schemas') |
393 directory = osp.join(CW_SOFTWARE_ROOT, 'schemas') |
398 else: |
394 else: |
399 directory = self.config.cube_dir(cube) |
395 directory = self.config.cube_dir(cube) |
400 sql_scripts = [] |
396 sql_scripts = glob(osp.join(directory, '*.%s.sql' % driver)) |
401 for fpath in glob(osp.join(directory, '*.sql.%s' % driver)): |
|
402 newname = osp.basename(fpath).replace('.sql.%s' % driver, |
|
403 '.%s.sql' % driver) |
|
404 warn('[3.5.6] rename %s into %s' % (fpath, newname), |
|
405 DeprecationWarning) |
|
406 sql_scripts.append(fpath) |
|
407 sql_scripts += glob(osp.join(directory, '*.%s.sql' % driver)) |
|
408 for fpath in sql_scripts: |
397 for fpath in sql_scripts: |
409 print '-> installing', fpath |
398 print '-> installing', fpath |
410 try: |
399 try: |
411 sqlexec(open(fpath).read(), self.session.system_sql, False, |
400 sqlexec(open(fpath).read(), self.session.system_sql, False, |
412 delimiter=';;') |
401 delimiter=';;') |
1247 # cleanup unused constraints |
1236 # cleanup unused constraints |
1248 self.rqlexec('DELETE CWConstraint C WHERE NOT X constrained_by C') |
1237 self.rqlexec('DELETE CWConstraint C WHERE NOT X constrained_by C') |
1249 if commit: |
1238 if commit: |
1250 self.commit() |
1239 self.commit() |
1251 |
1240 |
1252 @deprecated('[3.2] use sync_schema_props_perms(ertype, syncprops=False)') |
|
1253 def cmd_synchronize_permissions(self, ertype, commit=True): |
|
1254 self.cmd_sync_schema_props_perms(ertype, syncprops=False, commit=commit) |
|
1255 |
|
1256 # Workflows handling ###################################################### |
1241 # Workflows handling ###################################################### |
1257 |
1242 |
1258 def cmd_make_workflowable(self, etype): |
1243 def cmd_make_workflowable(self, etype): |
1259 """add workflow relations to an entity type to make it workflowable""" |
1244 """add workflow relations to an entity type to make it workflowable""" |
1260 self.cmd_add_relation_definition(etype, 'in_state', 'State') |
1245 self.cmd_add_relation_definition(etype, 'in_state', 'State') |
1306 """return default workflow for the given entity type""" |
1291 """return default workflow for the given entity type""" |
1307 rset = self.rqlexec('Workflow X WHERE ET default_workflow X, ET name %(et)s', |
1292 rset = self.rqlexec('Workflow X WHERE ET default_workflow X, ET name %(et)s', |
1308 {'et': etype}) |
1293 {'et': etype}) |
1309 return rset.get_entity(0, 0) |
1294 return rset.get_entity(0, 0) |
1310 |
1295 |
1311 # XXX remove once cmd_add_[state|transition] are removed |
|
1312 def _get_or_create_wf(self, etypes): |
|
1313 if not isinstance(etypes, (list, tuple)): |
|
1314 etypes = (etypes,) |
|
1315 rset = self.rqlexec('Workflow X WHERE X workflow_of ET, ET name %(et)s', |
|
1316 {'et': etypes[0]}) |
|
1317 if rset: |
|
1318 return rset.get_entity(0, 0) |
|
1319 return self.cmd_add_workflow('%s workflow' % ';'.join(etypes), etypes) |
|
1320 |
|
1321 @deprecated('[3.5] use add_workflow and Workflow.add_state method', |
|
1322 stacklevel=3) |
|
1323 def cmd_add_state(self, name, stateof, initial=False, commit=False, **kwargs): |
|
1324 """method to ease workflow definition: add a state for one or more |
|
1325 entity type(s) |
|
1326 """ |
|
1327 wf = self._get_or_create_wf(stateof) |
|
1328 state = wf.add_state(name, initial, **kwargs) |
|
1329 if commit: |
|
1330 self.commit() |
|
1331 return state.eid |
|
1332 |
|
1333 @deprecated('[3.5] use add_workflow and Workflow.add_transition method', |
|
1334 stacklevel=3) |
|
1335 def cmd_add_transition(self, name, transitionof, fromstates, tostate, |
|
1336 requiredgroups=(), conditions=(), commit=False, **kwargs): |
|
1337 """method to ease workflow definition: add a transition for one or more |
|
1338 entity type(s), from one or more state and to a single state |
|
1339 """ |
|
1340 wf = self._get_or_create_wf(transitionof) |
|
1341 tr = wf.add_transition(name, fromstates, tostate, requiredgroups, |
|
1342 conditions, **kwargs) |
|
1343 if commit: |
|
1344 self.commit() |
|
1345 return tr.eid |
|
1346 |
|
1347 @deprecated('[3.5] use Transition.set_transition_permissions method', |
|
1348 stacklevel=3) |
|
1349 def cmd_set_transition_permissions(self, treid, |
|
1350 requiredgroups=(), conditions=(), |
|
1351 reset=True, commit=False): |
|
1352 """set or add (if `reset` is False) groups and conditions for a |
|
1353 transition |
|
1354 """ |
|
1355 tr = self._cw.entity_from_eid(treid) |
|
1356 tr.set_transition_permissions(requiredgroups, conditions, reset) |
|
1357 if commit: |
|
1358 self.commit() |
|
1359 |
|
1360 @deprecated('[3.5] use iworkflowable.fire_transition("transition") or ' |
|
1361 'iworkflowable.change_state("state")', stacklevel=3) |
|
1362 def cmd_set_state(self, eid, statename, commit=False): |
|
1363 self._cw.entity_from_eid(eid).cw_adapt_to('IWorkflowable').change_state(statename) |
|
1364 if commit: |
|
1365 self.commit() |
|
1366 |
|
1367 # CWProperty handling ###################################################### |
1296 # CWProperty handling ###################################################### |
1368 |
1297 |
1369 def cmd_property_value(self, pkey): |
1298 def cmd_property_value(self, pkey): |
1370 """retreive the site-wide persistent property value for the given key. |
1299 """retreive the site-wide persistent property value for the given key. |
1371 |
1300 |
1455 """force reindexaction of entities of the given types or of all |
1384 """force reindexaction of entities of the given types or of all |
1456 indexable entity types |
1385 indexable entity types |
1457 """ |
1386 """ |
1458 from cubicweb.server.checkintegrity import reindex_entities |
1387 from cubicweb.server.checkintegrity import reindex_entities |
1459 reindex_entities(self.repo.schema, self.session, etypes=etypes) |
1388 reindex_entities(self.repo.schema, self.session, etypes=etypes) |
1460 |
|
1461 @deprecated('[3.5] use create_entity', stacklevel=3) |
|
1462 def cmd_add_entity(self, etype, *args, **kwargs): |
|
1463 """add a new entity of the given type""" |
|
1464 return self.cmd_create_entity(etype, *args, **kwargs).eid |
|
1465 |
1389 |
1466 @contextmanager |
1390 @contextmanager |
1467 def cmd_dropped_constraints(self, etype, attrname, cstrtype=None, |
1391 def cmd_dropped_constraints(self, etype, attrname, cstrtype=None, |
1468 droprequired=False): |
1392 droprequired=False): |
1469 """context manager to drop constraints temporarily on fs_schema |
1393 """context manager to drop constraints temporarily on fs_schema |