Skip to content

Instantly share code, notes, and snippets.

@TheCatPlusPlus
Created November 11, 2014 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheCatPlusPlus/063c75a5440934b5d880 to your computer and use it in GitHub Desktop.
Save TheCatPlusPlus/063c75a5440934b5d880 to your computer and use it in GitHub Desktop.
def make_revision(self, log):
log('Creating new VID for node {}', self.node['nid'])
result = self.db.query('''
INSERT INTO node_revision (nid, uid, title, log, timestamp, status, vuuid)
VALUES (%s, 1, %s, %s, UNIX_TIMESTAMP(), 1, %s)
''', self.node['nid'], self.node['title'], '[auto] {}'.format(log), uuid.uuid4())
vid = result.last_id
log('Setting VID for node {} to {}', self.node['nid'], vid)
self.db.query('''
UPDATE node SET vid = %s WHERE nid = %s
''', vid, self.node['nid'])
self.node['vid'] = vid
for name, field_data in self.fields.iteritems():
log('Creating revision for field {} for node {}', name, self.node['nid'])
self.db.query('''
DELETE FROM field_data_{field} WHERE
entity_id = %s AND entity_type = 'node'
''', field = name)
for datum in field_data:
datum['revision_id'] = vid
columns = []
places = []
values = []
for key, value in datum.iteritems():
columns.append(key)
values.append(value)
places.append('%s')
for type in ('data', 'revision'):
self.db.query('''
INSERT INTO field_{type}_{field}
({columns}) VALUES ({places})
''', *values, type = type, field = name, places = ', '.join(places), columns = ', '.join(columns))
return vid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment