public function scopeUpdateSource($query, $variableId, $newDatasourceId) { if (!empty($newDatasourceId)) { $variable = Variable::find($variableId); //is it event necessary to update source? if ($variable->fk_dsr_id != $newDatasourceId) { //it is update both variable source all sources of all variable values $variable->fk_dsr_id = $newDatasourceId; $variable->save(); //update all variable values DataValue::where('fk_var_id', $variable->id)->update(array('fk_dsr_id' => $newDatasourceId)); } } }
/** * Run the migrations. * * @return void */ public function up() { DB::transaction(function () { DataValue::where('fk_ent_id', 341)->update(array('fk_ent_id' => 355)); Entity::where('id', 341)->delete(); $charts = Chart::all(); foreach ($charts as $chart) { $config = json_decode($chart->config); $countries = $config->{'selected-countries'}; if (empty($countries)) { continue; } foreach ($countries as $country) { if ($country->id == "341") { echo "Updating chart config for " . $chart->id . "\n"; $country->id = "355"; $country->name = "World"; } } $chart->config = json_encode($config); $chart->save(); } }); }
public function updateSource(Variable $variable, $newDatasourceId) { if (!empty($newDatasourceId)) { //is it event necessary to update source? if ($variable->fk_dsr_id != $newDatasourceId) { //it is update both variable source all sources of all variable values $variable->fk_dsr_id = $newDatasourceId; $variable->save(); //update all variable values DataValue::where('fk_var_id', $variable->id)->update(array('fk_dsr_id' => $newDatasourceId)); Cache::flush(); } } }