Commit 18a6eea3 authored by Matthias Larisch's avatar Matthias Larisch

Fix db fixup + some queries using foodsaver

Update migration to fix most of the foreign keys including adding
constraints to the proposal.

Apply same changes to code that has already been fixed in previous
commits.
TODO look through other queries involving the same tables before putting
this live.

Sorry for whitespace checkin, I didn't manage to configure my Atom
correctly :(
parent eafdc662
Pipeline #7961316 failed with stage
in 2 minutes and 6 seconds
This diff is collapsed.
......@@ -3,53 +3,53 @@ class FoodsaverModel extends Model
{
/**
* Lists foodsaver having a bezirk
*
*
* @param Integer $bezirk_id
*/
public function listFoodsaver($bezirk_id)
{
return $this->q('
SELECT
fs.id,
fs.id,
fs.name,
fs.nachname,
fs.photo,
fs.sleep_status,
CONCAT("#",fs.id) AS href
FROM
'.PREFIX.'foodsaver fs,
'.PREFIX.'foodsaver_has_bezirk hb
WHERE
fs.id = hb.foodsaver_id
AND
fs.deleted = 0
AND
fs.deleted_at IS NULL
AND
hb.bezirk_id = '.(int)$bezirk_id.'
ORDER BY
fs.last_login DESC
');
}
/**
* Adds a list of foodsaver to an defined bezirk
*
*
* @param array $foodsaver_ids
* @param integer $bezirk_id
*/
public function addFoodsaverToBezirk($foodsaver_ids, $bezirk_id)
{
$values = array();
foreach ($foodsaver_ids as $id)
{
$values[] = '('.(int)$bezirk_id.','.(int)$id.',1)';
}
return $this->insert('
INSERT IGNORE INTO '.PREFIX.'foodsaver_has_bezirk
(
......@@ -61,24 +61,24 @@ class FoodsaverModel extends Model
'.implode(',', $values).'
');
}
public function delfrombezirk($bezirk_id, $foodsaver_id)
{
$this->del('
DELETE FROM
'.PREFIX.'botschafter
WHERE
bezirk_id = '.(int)$bezirk_id.'
AND
foodsaver_id = '.(int)$foodsaver_id.'
');
return $this->del('
DELETE FROM
DELETE FROM
'.PREFIX.'foodsaver_has_bezirk
WHERE
bezirk_id = '.(int)$bezirk_id.'
......@@ -86,11 +86,11 @@ class FoodsaverModel extends Model
foodsaver_id = '.(int)$foodsaver_id.'
');
}
public function loadFoodsaver($fsid)
{
return $this->qRow('
SELECT
SELECT
id,
name,
nachname,
......@@ -101,12 +101,12 @@ class FoodsaverModel extends Model
FROM
'.PREFIX.'foodsaver
WHERE
id = '.(int)$fsid.'
AND
deleted = 0
id = '.(int)$fsid.'
AND
deleted_at IS NULL
');
}
}
\ No newline at end of file
}
......@@ -518,7 +518,7 @@ class ManualDb extends Db
FROM '.PREFIX.'betrieb_team bt
WHERE bt.verantwortlich = 1 AND
WHERE bt.verantwortlich = 1 AND
active = 1 AND
bt.betrieb_id = '.$this->intval($bid).'
');
......@@ -597,8 +597,8 @@ class ManualDb extends Db
{
if($betrieb = $this->getMyBetrieb($bid))
{
if(!is_null($betrieb['team_conversation_id']))
if(!is_null($betrieb['team_conversation_id']))
{
$msg = loadModel('msg');
$msg->sendMessage($betrieb['team_conversation_id'],$message);
......@@ -1332,9 +1332,9 @@ class ManualDb extends Db
$verified = '`verified` = 0,';
$bids = $this->q('
SELECT bt.betrieb_id as id
SELECT bt.betrieb_id as id
FROM '.PREFIX.'betrieb_team bt
WHERE bt.foodsaver_id = '.$this->intval($id).'
WHERE bt.foodsaver_id = '.$this->intval($id).'
');
$betrieb = loadModel('betrieb');
//Delete from Companies
......@@ -1363,11 +1363,11 @@ class ManualDb extends Db
for ($i = 1; $i <= 7; $i++) {
$this->insert('
INSERT INTO '.PREFIX.'quiz_session (
foodsaver_id,
quiz_id,
foodsaver_id,
quiz_id,
`status`,
time_start
)
)
VALUES
(
'.$this->intval($id).',
......@@ -1504,37 +1504,37 @@ class ManualDb extends Db
$this->del('
DELETE FROM '.PREFIX.'betrieb_team
DELETE FROM '.PREFIX.'betrieb_team
WHERE foodsaver_id = '.(int)$id.'
');
$this->del('
DELETE FROM '.PREFIX.'apitoken
DELETE FROM '.PREFIX.'apitoken
WHERE foodsaver_id = '.(int)$id.'
');
$this->del('
DELETE FROM '.PREFIX.'basket_anfrage
DELETE FROM '.PREFIX.'basket_anfrage
WHERE foodsaver_id = '.(int)$id.'
');
$this->del('
DELETE FROM '.PREFIX.'botschafter
DELETE FROM '.PREFIX.'botschafter
WHERE foodsaver_id = '.(int)$id.'
');
$this->del('
DELETE FROM '.PREFIX.'buddy
DELETE FROM '.PREFIX.'buddy
WHERE foodsaver_id = '.(int)$id.' OR buddy_id = '.(int)$id.'
');
$this->del('
DELETE FROM '.PREFIX.'event
DELETE FROM '.PREFIX.'event
WHERE foodsaver_id = '.(int)$id.'
');
$this->del('
DELETE FROM '.PREFIX.'fairteiler_follower
DELETE FROM '.PREFIX.'fairteiler_follower
WHERE foodsaver_id = '.(int)$id.'
');
......@@ -1593,69 +1593,9 @@ class ManualDb extends Db
WHERE foodsaver_id = '.(int)$id.' OR bot_id = '.(int)$id.'
');
return $this->update('
UPDATE `'.PREFIX.'foodsaver`
SET
`deleted` = 1,
`deleted_at` = NOW(),
`position` = "",
`verified` = 0,
`rolle` = 0,
`type` = 0,
`plz` = "",
`stadt`= "",
`lat`= "",
`lon` = "",
`photo` = "",
`photo_public` = 0,
`email` = NULL,
`passwd` = "",
`name`= "",
`admin` = 0,
`nachname` = "",
`anschrift` = "",
`telefon`="",
`tox`="",
`homepage` = "",
`github` = "",
`twitter` = "",
`handy` = "",
`geschlecht` = NULL,
`geb_datum` = NULL,
`fs_id` = NULL,
`orgateam`= 0,
`active` = 0,
`data`="",
`about_me_public` = "",
`newsletter` = 0,
`token` = "",
`infomail_message` = ",
`last_login` = NULL,
`stat_fetchweight` = 0,
`stat_fetchcount` = 0,
`stat_ratecount` = 0,
`stat_rating` = 0,
`stat_postcount` = 0,
`stat_buddycount` = 0,
`stat_bananacount` = 0,
`stat_fetchrate` = 0,
`sleep_status` = 0,
`sleep_from` = NULL,`sleep_until`= NULL,
`sleep_msg`= "",
`last_mid` = NULL,
`option` = "",
`beta` = 0,
`fs_password` = "",
`quiz_rolle`=0,
`contact_public` = 0
WHERE
id = '.(int)$id
);
$this->del('DELETE FROM '.PREFIX.'foodsaver WHERE foodsaver_id = '.(int)$id);
return $this->q('INSERT INTO fs_foodsaver(id, deleted_at) VALUES ('.(int)$id.', NOW())');
}
public function getBezirk($id = false)
......@@ -3023,7 +2963,7 @@ class ManualDb extends Db
');
$springerMembers = $this->getBetriebSpringer($bid);
foreach($springerMembers['id'] as $fs_id)
{
......@@ -3093,7 +3033,7 @@ class ManualDb extends Db
'.$this->intval($data['sticker']).',
'.$this->intval($data['abholmenge']).'
)');
$this->createTeamConversation($id);
$this->createSpringerConversation($id);
......
This diff is collapsed.
REPLACE INTO `fs_foodsaver` VALUES (151030,0,'',0,'0000-00-00 00:00:00','',0,0,0,0,'10557','Berlin','52.5250839','13.369402','',0,'user1@example.com','bafc1bcb62e51692a32aeb717ccc8a42','User',NULL,'One','Europaplatz 1','','','','','',NULL,0,NULL,0,'2016-07-22 20:01:45',0,1,'','',1,'57927ba974bc07.93176475',1,'2016-07-22 20:14:18',0.00,0,0,0.00,0,0,0,100.00,0,'0000-00-00','0000-00-00','','0000-00-00','',0,NULL,0,0),(151031,0,'',0,'0000-00-00 00:00:00','',0,0,0,0,'','Frankfurt an der Oder','52.3472237','14.5505673','',0,'user2@example.com','60448ca3a0d65768f52907f932c84bf1','User',NULL,'Two',' ','','','','','',NULL,0,NULL,0,'2016-07-22 20:15:32',0,1,'','',1,'57927ee4e163f2.22045910',1,'0000-00-00 00:00:00',0.00,0,0,0.00,0,0,0,100.00,0,'0000-00-00','0000-00-00','','0000-00-00','',0,NULL,0,0);
REPLACE INTO `fs_foodsaver` VALUES (151032,241,'',1,'0000-00-00 00:00:00','',0,0,3,0,'10557','Berlin','52.5250839','13.369402','',0,'userbot@example.com','7c8a4e4fcf07150c5afe439887b4e091','User',NULL,'Bot','Europaplatz 5','','','','','',NULL,0,NULL,0,'2016-07-22 20:01:45',0,1,'','',1,'57927ba974bc07.93176475',1,'2016-07-22 20:14:18',0.00,0,0,0.00,0,0,0,100.00,0,'0000-00-00','0000-00-00','','0000-00-00','',0,NULL,3,0);
REPLACE INTO `fs_foodsaver` VALUES (151030,0,'',0,'0000-00-00 00:00:00','',0,0,0,0,'10557','Berlin','52.5250839','13.369402','',0,'user1@example.com','bafc1bcb62e51692a32aeb717ccc8a42','User',NULL,'One','Europaplatz 1','','','','','',NULL,0,NULL,0,'2016-07-22 20:01:45',0,1,'','',1,'57927ba974bc07.93176475',1,'2016-07-22 20:14:18',0.00,0,0,0.00,0,0,0,100.00,0,'0000-00-00','0000-00-00','','0000-00-00','',0,NULL,0,0,NULL),(151031,0,'',0,'0000-00-00 00:00:00','',0,0,0,0,'','Frankfurt an der Oder','52.3472237','14.5505673','',0,'user2@example.com','60448ca3a0d65768f52907f932c84bf1','User',NULL,'Two',' ','','','','','',NULL,0,NULL,0,'2016-07-22 20:15:32',0,1,'','',1,'57927ee4e163f2.22045910',1,'0000-00-00 00:00:00',0.00,0,0,0.00,0,0,0,100.00,0,'0000-00-00','0000-00-00','','0000-00-00','',0,NULL,0,0,NULL);
REPLACE INTO `fs_foodsaver` VALUES (151032,241,'',1,'0000-00-00 00:00:00','',0,0,3,0,'10557','Berlin','52.5250839','13.369402','',0,'userbot@example.com','7c8a4e4fcf07150c5afe439887b4e091','User',NULL,'Bot','Europaplatz 5','','','','','',NULL,0,NULL,0,'2016-07-22 20:01:45',0,1,'','',1,'57927ba974bc07.93176475',1,'2016-07-22 20:14:18',0.00,0,0,0.00,0,0,0,100.00,0,'0000-00-00','0000-00-00','','0000-00-00','',0,NULL,3,0,NULL);
REPLACE INTO `fs_botschafter` (`foodsaver_id`, `bezirk_id`) VALUES ('151032', '241');
REPLACE INTO `fs_foodsaver_has_bezirk` (`foodsaver_id`, `bezirk_id`, `active`) VALUES ('151032', '241', '1');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment