|
8 | 8 | use CustomerManagementFrameworkBundle\Model\ActivityStoreEntry\ActivityStoreEntryInterface; |
9 | 9 | use CustomerManagementFrameworkBundle\Model\CustomerInterface; |
10 | 10 | use Doctrine\DBAL\Connection; |
| 11 | +use Doctrine\DBAL\Exception\TableNotFoundException; |
11 | 12 | use Pimcore\Db; |
12 | 13 | use Pimcore\Model\DataObject\Concrete; |
13 | 14 | use Zend\Paginator\Paginator; |
14 | 15 |
|
15 | 16 | abstract class SqlActivityStore |
16 | 17 | { |
17 | 18 | const ACTIVITIES_TABLE = 'plugin_cmf_activities'; |
| 19 | + const ACTIVITIES_METADATA_TABLE = 'plugin_cmf_activities_metadata'; |
18 | 20 | const DELETIONS_TABLE = 'plugin_cmf_deletions'; |
19 | 21 |
|
20 | 22 | public function insertActivityIntoStore(ActivityInterface $activity) |
@@ -78,19 +80,49 @@ protected function saveActivityStoreEntry(ActivityStoreEntryInterface $entry, Ac |
78 | 80 | $data['md5'] = md5(serialize($md5Data)); |
79 | 81 | $data['modificationDate'] = $time; |
80 | 82 |
|
81 | | - if ($entry->getId()) { |
82 | | - $this->getActivityStoreConnection()->update( |
83 | | - self::ACTIVITIES_TABLE, |
84 | | - $data, |
85 | | - 'id = '.$entry->getId() |
86 | | - ); |
87 | | - } else { |
88 | | - $data['creationDate'] = $time; |
89 | | - $db->insert( |
90 | | - self::ACTIVITIES_TABLE, |
91 | | - $data |
92 | | - ); |
93 | | - $entry->setId($db->lastInsertId()); |
| 83 | + $db->beginTransaction(); |
| 84 | + |
| 85 | + try { |
| 86 | + |
| 87 | + if ($entry->getId()) { |
| 88 | + $this->getActivityStoreConnection()->update( |
| 89 | + self::ACTIVITIES_TABLE, |
| 90 | + $data, |
| 91 | + 'id = '.$entry->getId() |
| 92 | + ); |
| 93 | + } else { |
| 94 | + $data['creationDate'] = $time; |
| 95 | + $db->insert( |
| 96 | + self::ACTIVITIES_TABLE, |
| 97 | + $data |
| 98 | + ); |
| 99 | + $entry->setId($db->lastInsertId()); |
| 100 | + } |
| 101 | + |
| 102 | + try { |
| 103 | + $db->query('delete from ' . self::ACTIVITIES_METADATA_TABLE . ' where activityId = ' . intval($entry->getId())); |
| 104 | + |
| 105 | + foreach($entry->getMetadata() as $key => $data) { |
| 106 | + |
| 107 | + $db->insert( |
| 108 | + self::ACTIVITIES_METADATA_TABLE, |
| 109 | + [ |
| 110 | + 'activityId' => $entry->getId(), |
| 111 | + 'key' => $key, |
| 112 | + 'data' => $data |
| 113 | + ] |
| 114 | + ); |
| 115 | + } |
| 116 | + } catch(TableNotFoundException $ex) { |
| 117 | + $this->getLogger()->error(sprintf('table %s not found - please press the update button of the CMF bundle in the extension manager', self::ACTIVITIES_METADATA_TABLE)); |
| 118 | + $db->rollBack(); |
| 119 | + } |
| 120 | + |
| 121 | + $db->commit(); |
| 122 | + |
| 123 | + } catch(\Exception $e) { |
| 124 | + $this->getLogger()->error(sprintf('save activity (%s) failed: %s', $entry->getId(), $e->getMessage())); |
| 125 | + $db->rollBack(); |
94 | 126 | } |
95 | 127 | } |
96 | 128 |
|
|
0 commit comments