8000 bug #56 fix: change executeQuery method to executeUpdate for writing … · jderusse/symfony@e4edaf8 · GitHub
[go: up one dir, main page]

Skip to content

Commit e4edaf8

Browse files
committed
bug symfony#56 fix: change executeQuery method to executeUpdate for writing operations (Briones)
This PR was merged into the 3.0-dev branch. Discussion ---------- fix: change executeQuery method to executeUpdate for writing operations I noticed in a project that uses this library that this is using `executeQuery` doctrine method for writing operations, for systems that has a `master` and `slave` databases it results in errors since the slave normally is configured to be read-only and using `executeQuery` leads to Doctrine trying to use the slave read-only instance to insert, delete or update data, causing errors like the following in Mysql: ``` Error Code: 1290. The MySQL server is running with the –read-only option so it cannot execute this statement ``` This PR changes the `executeQuery` for `executeUpdate` for the writing cases. Commits ------- 8e5d155 fix: change executeQuery method to executeUpdate for writing operations
2 parents c4757ce + 8e5d155 commit e4edaf8

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

Dbal/MutableAclProvider.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function createAcl(ObjectIdentityInterface $oid)
6060
$this->createObjectIdentity($oid);
6161

6262
$pk = $this->retrieveObjectIdentityPrimaryKey($oid);
63-
$this->connection->executeQuery($this->getInsertObjectIdentityRelationSql($pk, $pk));
63+
$this->connection->executeUpdate($this->getInsertObjectIdentityRelationSql($pk, $pk));
6464

6565
$this->connection->commit();
6666
} catch (\Exception $e) {
@@ -119,7 +119,7 @@ public function deleteAcl(ObjectIdentityInterface $oid)
119119
*/
120120
public function deleteSecurityIdentity(SecurityIdentityInterface $sid)
121121
{
122-
$this->connection->executeQuery($this->getDeleteSecurityIdentityIdSql($sid));
122+
$this->connection->executeUpdate($this->getDeleteSecurityIdentityIdSql($sid));
123123
}
124124

125125
/**
@@ -334,7 +334,7 @@ public function updateAcl(MutableAclInterface $acl)
334334

335335
// persist any changes to the acl_object_identities table
336336
if (count($sets) > 0) {
337-
$this->connection->executeQuery($this->getUpdateObjectIdentitySql($acl->getId(), $sets));
337+
$this->connection->executeUpdate($this->getUpdateObjectIdentitySql($acl->getId(), $sets));
338338
}
339339

340340
$this->connection->commit();
@@ -373,7 +373,7 @@ public function updateAcl(MutableAclInterface $acl)
373373
*/
374374
public function updateUserSecurityIdentity(UserSecurityIdentity $usid, $oldUsername)
375375
{
376-
$this->connection->executeQuery($this->getUpdateUserSecurityIdentitySql($usid, $oldUsername));
376+
$this->connection->executeUpdate($this->getUpdateUserSecurityIdentitySql($usid, $oldUsername));
377377
}
378378

379379
/**
@@ -750,7 +750,7 @@ private function createObjectIdentity(ObjectIdentityInterface $oid)
750750
{
751751
$classId = $this->createOrRetrieveClassId($oid->getType());
752752

753-
$this->connection->executeQuery($this->getInsertObjectIdentitySql($oid->getIdentifier(), $classId, true));
753+
$this->connection->executeUpdate($this->getInsertObjectIdentitySql($oid->getIdentifier(), $classId, true));
754754
}
755755

756756
/**
@@ -768,7 +768,7 @@ private function createOrRetrieveClassId($classType)
768768
return $id;
769769
}
770770

771-
$this->connection->executeQuery($this->getInsertClassSql($classType));
771+
$this->connection->executeUpdate($this->getInsertClassSql($classType));
772772

773773
return $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchColumn();
774774
}
@@ -789,7 +789,7 @@ private function createOrRetrieveSecurityIdentityId(SecurityIdentityInterface $s
789789
return $id;
790790
}
791791

792-
$this->connection->executeQuery($this->getInsertSecurityIdentitySql($sid));
792+
$this->connection->executeUpdate($this->getInsertSecurityIdentitySql($sid));
793793

794794
return $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchColumn();
795795
}
@@ -801,7 +801,7 @@ private function createOrRetrieveSecurityIdentityId(SecurityIdentityInterface $s
801801
*/
802802
private function deleteAccessControlEntries($oidPK)
803803
{
804-
$this->connection-> 628C ;executeQuery($this->getDeleteAccessControlEntriesSql($oidPK));
804+
$this->connection->executeUpdate($this->getDeleteAccessControlEntriesSql($oidPK));
805805
}
806806

807807
/**
@@ -811,7 +811,7 @@ private function deleteAccessControlEntries($oidPK)
811811
*/
812812
private function deleteObjectIdentity($pk)
813813
{
814-
$this->connection->executeQuery($this->getDeleteObjectIdentitySql($pk));
814+
$this->connection->executeUpdate($this->getDeleteObjectIdentitySql($pk));
815815
}
816816

817817
/**
@@ -821,7 +821,7 @@ private function deleteObjectIdentity($pk)
821821
*/
822822
private function deleteObjectIdentityRelations($pk)
823823
{
824-
$this->connection->executeQuery($this->getDeleteObjectIdentityRelationsSql($pk));
824+
$this->connection->executeUpdate($this->getDeleteObjectIdentityRelationsSql($pk));
825825
}
826826

827827
/**
@@ -832,12 +832,12 @@ private function deleteObjectIdentityRelations($pk)
832832
private function regenerateAncestorRelations(AclInterface $acl)
833833
{
834834
$pk = $acl->getId();
835-
$this->connection->executeQuery($this->getDeleteObjectIdentityRelationsSql($pk));
836-
$this->connection->executeQuery($this->getInsertObjectIdentityRelationSql($pk, $pk));
835+
$this->connection->executeUpdate($this->getDeleteObjectIdentityRelationsSql($pk));
836+
$this->connection->executeUpdate($this->getInsertObjectIdentityRelationSql($pk, $pk));
837837

838838
$parentAcl = $acl->getParentAcl();
839839
while (null !== $parentAcl) {
840-
$this->connection->executeQuery($this->getInsertObjectIdentityRelationSql($pk, $parentAcl->getId()));
840+
$this->connection->executeUpdate($this->getInsertObjectIdentityRelationSql($pk, $parentAcl->getId()));
841841

842842
$parentAcl = $parentAcl->getParentAcl();
843843
}
@@ -873,7 +873,7 @@ private function updateNewFieldAceProperty($name, array $changes)
873873

874874
$objectIdentityId = $name === 'classFieldAces' ? null : $ace->getAcl()->getId();
875875

876-
$this->connection->executeQuery($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, $field, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
876+
$this->connection->executeUpdate($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, $field, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
877877
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, $field, $i))->fetchColumn();
878878
$this->loadedAces[$aceId] = $ace;
879879

@@ -909,7 +909,7 @@ private function updateOldFieldAceProperty($name, array $changes)
909909
$ace = $old[$i];
910910

911911
if (!isset($currentIds[$ace->getId()])) {
912-
$this->connection->executeQuery($this->getDeleteAccessControlEntrySql($ace->getId()));
912+
$this->connection->executeUpdate($this->getDeleteAccessControlEntrySql($ace->getId()));
913913
unset($this->loadedAces[$ace->getId()]);
914914
}
915915
}
@@ -947,7 +947,7 @@ private function updateNewAceProperty($name, array $changes)
947947

948948
$objectIdentityId = $name === 'classAces' ? null : $ace->getAcl()->getId();
949949

950-
$this->connection->executeQuery($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, null, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
950+
$this->connection->executeUpdate($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, null, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
951951
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, null, $i))->fetchColumn();
952952
$this->loadedAces[$aceId] = $ace;
953953

@@ -981,7 +981,7 @@ private function updateOldAceProperty($name, array $changes)
981981
$ace = $old[$i];
982982

983983
if (!isset($currentIds[$ace->getId()])) {
984-
$this->connection->executeQuery($this->getDeleteAccessControlEntrySql($ace->getId()));
984+
$this->connection->executeUpdate($this->getDeleteAccessControlEntrySql($ace->getId()));
985985
unset($this->loadedAces[$ace->getId()]);
986986
}
987987
}
@@ -1029,6 +1029,6 @@ private function updateAce(\SplObjectStorage $aces, $ace)
10291029
$sets[] = sprintf('audit_failure = %s', $this->connection->getDatabasePlatform()->convertBooleans($propertyChanges['auditFailure'][1]));
10301030
}
10311031

1032-
$this->connection->executeQuery($this->getUpdateAccessControlEntrySql($ace->getId(), $sets));
1032+
$this->connection->executeUpdate($this->getUpdateAccessControlEntrySql($ace->getId(), $sets));
10331033
}
10341034
}

Tests/Dbal/MutableAclProviderTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public function testUpdateDoesNothingWhenThereAreNoChanges()
262262
;
263263
$con
264264
->expects($this->never())
265-
->method('executeQuery')
265+
->method('executeUpdate')
266266
;
267267

268268
$provider = new MutableAclProvider($con, new PermissionGrantingStrategy(), array());
@@ -477,12 +477,12 @@ protected function importAcls(AclProvider $provider, array $data)
477477
$aclIds[$name] = $aclId;
478478

479479
$sql = $this->callMethod($provider, 'getInsertObjectIdentityRelationSql', array($aclId, $aclId));
480-
$con->executeQuery($sql);
480+
$con->executeUpdate($sql);
481481

482482
if (isset($aclData['parent_acl'])) {
483483
if (isset($aclIds[$aclData['parent_acl']])) {
484-
$con->executeQuery('UPDATE acl_object_identities SET parent_object_identity_id = '.$aclIds[$aclData['parent_acl']].' WHERE id = '.$aclId);
485-
$con->executeQuery($this->callMethod($provider, 'getInsertObjectIdentityRelationSql', array($aclId, $aclIds[$aclData['parent_acl']])));
484+
$con->executeUpdate('UPDATE acl_object_identities SET parent_object_identity_id = '.$aclIds[$aclData['parent_acl']].' WHERE id = '.$aclId);
485+
$con->executeUpdate($this->callMethod($provider, 'getInsertObjectIdentityRelationSql', array($aclId, $aclIds[$aclData['parent_acl']])));
486486
} else {
487487
$parentAcls[$aclId] = $aclData['parent_acl'];
488488
}
@@ -494,8 +494,8 @@ protected function importAcls(AclProvider $provider, array $data)
494494
throw new \InvalidArgumentException(sprintf('"%s" does not exist.', $name));
495495
}
496496

497-
$con->executeQuery(sprintf('UPDATE acl_object_identities SET parent_object_identity_id = %d WHERE id = %d', $aclIds[$name], $aclId));
498-
$con->executeQuery($this->callMethod($provider, 'getInsertObjectIdentityRelationSql', array($aclId, $aclIds[$name])));
497+
$con->executeUpdate(sprintf('UPDATE acl_object_identities SET parent_object_identity_id = %d WHERE id = %d', $aclIds[$name], $aclId));
498+
$con->executeUpdate($this->callMethod($provider, 'getInsertObjectIdentityRelationSql', array($aclId, $aclIds[$name])));
499499
}
500500

501501
$con->commit();

0 commit comments

Comments
 (0)
0