-
-
Save TheCatPlusPlus/063c75a5440934b5d880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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