);
} else {
try {
- $this->zdb->connection->beginTransaction();
$ids = $this->getIdsToRemove($args, $post);
);
$success = true;
}
- $this->zdb->connection->commit();
} catch (\Exception $e) {
- $this->zdb->connection->rollBack();
Analog::log(
'An error occurred on delete | ' . $e->getMessage(),
Analog::ERROR
)
;
}
+
+ /**
+ * Drops a table
+ *
+ * @param string $table Table name, without prefix
+ * @param boolean $maymiss Whether the table can be missing, defaults to false
+ *
+ * @return void
+ */
+ public function drop($table, $maymiss = false)
+ {
+ $sql = 'DROP TABLE ';
+ if ($maymiss === true) {
+ $sql .= 'IF EXISTS ';
+ }
+ $sql .= PREFIX_DB . $table;
+ $this->db->query(
+ $sql,
+ \Laminas\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
+ );
+ }
}
$contents_table = self::getFixedValuesTableName($this->id, true);
try {
+ $this->zdb->drop($contents_table, true);
$this->zdb->connection->beginTransaction();
- $this->zdb->db->query(
- 'DROP TABLE IF EXISTS ' . $contents_table,
- \Laminas\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
- );
$field_size = ((int)$this->size > 0) ? $this->size : 1;
$this->zdb->db->query(
'CREATE TABLE ' . $contents_table .
);
$this->zdb->connection->commit();
} catch (\Exception $e) {
- $this->zdb->connection->rollBack();
+ if ($this->zdb->connection->inTransaction()) {
+ //because of DROP autocommit on mysql...
+ $this->zdb->connection->rollBack();
+ }
Analog::log(
'Unable to manage fields values table ' .
$contents_table . ' | ' . $e->getMessage(),
public function remove()
{
try {
+ if ($this->hasFixedValues()) {
+ $contents_table = self::getFixedValuesTableName($this->id);
+ $this->zdb->drop($contents_table);
+ }
+
$this->zdb->connection->beginTransaction();
$old_rank = $this->index;
throw new \RuntimeException('Unable to remove field ' . $this->id . '!');
}
- if ($this->hasFixedValues()) {
- $contents_table = self::getFixedValuesTableName($this->id);
- $this->zdb->db->query(
- 'DROP TABLE IF EXISTS ' . $contents_table,
- \Laminas\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
- );
- }
$this->deleteTranslation($this->name);
$this->zdb->connection->commit();
+
return true;
} catch (\Exception $e) {
- $this->zdb->connection->rollBack();
+ if ($this->zdb->connection->inTransaction()) {
+ //because of DROP autocommit on mysql...
+ $this->zdb->connection->rollBack();
+ }
Analog::log(
'An error occurred deleting field | ' . $e->getMessage(),
Analog::ERROR
{
$this->toremind = array();
$select = $zdb->select(Members::TABLE, 'a');
+ $select->columns([Members::PK, 'date_echeance']);
$select->join(
array('r' => PREFIX_DB . self::TABLE),
'a.' . Members::PK . '=r.reminder_dest',
array(
'last_reminder' => new Expression('MAX(reminder_date)'),
- 'reminder_type'
+ 'reminder_type' => new Expression('MAX(reminder_type)')
),
$select::JOIN_LEFT
)->join(
array('p' => PREFIX_DB . Members::TABLE),
'a.parent_id=p.' . Members::PK,
- array('email_adh'),
+ array(),
$select::JOIN_LEFT
)->where('(a.email_adh != \'\' OR p.email_adh != \'\')')
->where('a.activite_adh=true')
);
}
- $select->group('a.id_adh')->group('r.reminder_type')->group('p.email_adh');
+ $select->group('a.id_adh');
$results = $zdb->execute($select);
foreach ($results as $r) {
+ if ($r->reminder_type < $type) {
+ //sent impending, but is now late. reset last remind.
+ $r->reminder_type = $type;
+ $r->last_reminder = '';
+ }
+
if ($r->reminder_type === null || (int)$r->reminder_type === $type) {
$date_checked = false;
sort($expected);
$this->array($tables)
- ->hasSize(count($expected))
+ ->hasSize(count($expected), print_r($tables, true) . ' ' . print_r($expected, true))
->isIdenticalTo($expected);
}
private $request;
private $response;
private $mocked_router;
+ private $contents_table = null;
/**
* Set up tests
*/
public function beforeTestMethod($testMethod)
{
+ $this->contents_table = null;
$this->mocked_router = new \mock\Slim\Router();
$this->calling($this->mocked_router)->pathFor = function ($name, $params) {
return $name;
]
]);
$this->zdb->execute($delete);
+
+ if ($this->contents_table !== null) {
+ $this->zdb->drop($this->contents_table);
+ }
}
/**
$this->zdb->execute($delete);
$delete = $this->zdb->delete(\Galette\Entity\DynamicFieldsHandle::TABLE);
$this->zdb->execute($delete);
+ //cleanup dynamic choices table
+ $this->contents_table = $cdf->getFixedValuesTableName($cdf->getId());
//new dynamic field, of type date.
$cfield_data = [