Changeset 2243
- Timestamp:
- 05/21/19 17:30:15 (5 years ago)
- Location:
- trunk/LATMOS-Accounts
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/Changes
r2119 r2243 1 6.0.1 2 - Schema upgrade is now done automatically by la-sync-manager (update 3 module), or manually using la-sql-upgrade 4 Using a not up to date database will fail. 5 1 6 5.2.23 2 7 - add physicalDeliveryOfficeName attribute to nethost -
trunk/LATMOS-Accounts/README
r1 r2243 24 24 DEPENDENCIES 25 25 26 This module requires these other modules and libraries:27 28 blah blah blah29 30 26 COPYRIGHT AND LICENCE 31 27 -
trunk/LATMOS-Accounts/bin/la-sql-upgrade
r2085 r2243 45 45 $| = 1; # autoflush 46 46 47 if ($nocommit) { 48 $ENV{LA_NO_COMMIT} = 1; 49 } 50 47 51 my $LA = LATMOS::Accounts->new($config, noacl => 1); 48 my $labase = $LA-> base($base);52 my $labase = $LA->_load_base($base); 49 53 $labase->unexported(1); 50 51 require LATMOS::Accounts::Bases::Sql::upgrade;52 54 53 55 $labase->SchemaUpgrade() or die "An error occur"; 54 56 55 if ($nocommit) {56 $labase->rollback;57 } else {58 $labase->commit;59 }60 57 print "Process terminated successfully\n"; -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts.pm
r2202 r2243 134 134 my ($self, $section) = @_; 135 135 # this method perform a cache 136 $self->_load_base($section || $self->default_base_name); 136 my $base = $self->_load_base($section || $self->default_base_name); 137 138 $base->load or do { 139 la_log(LA_ERR, "%s didn't load", $base->label); 140 return; 141 }; 142 $base; 137 143 } 138 144 … … 166 172 return; 167 173 }; 168 $base->load or do {169 la_log(LA_ERR, "%s didn't load", $base->label);170 return;171 };172 $base;173 174 } 174 175 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm
r2236 r2243 18 18 our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; 19 19 20 sub SCHEMA_VERSION { 3 1};20 sub SCHEMA_VERSION { 32 }; 21 21 22 22 =head1 NAME … … 95 95 $self->log(LA_DEBUG, 'New connection to DB'); 96 96 97 {98 my $sv = $self->get_global_value('schema_version') || 1;99 if ($sv < SCHEMA_VERSION) {100 require LATMOS::Accounts::Bases::Sql::upgrade;101 if ($self->SchemaUpgrade()) {102 $self->commit;103 } else {104 $self->rollback;105 return;106 }107 }108 }109 110 $self->{_db}->commit;111 97 return $self->{_db}; 112 98 } 113 99 } 114 100 101 sub IsSchemaUpToDate { 102 my ($self) = @_; 103 104 my $sv = $self->get_global_value('schema_version') || 1; 105 106 return $sv == SCHEMA_VERSION; 107 } 108 109 sub SchemaUpgrade { 110 my ($self) = @_; 111 112 if (!$self->IsSchemaUpToDate) { 113 require LATMOS::Accounts::Bases::Sql::upgrade; 114 if ($self->_SchemaUpgrade()) { 115 $self->commit; 116 } else { 117 $self->rollback; 118 return; 119 } 120 } else { 121 return 1; 122 } 123 } 124 115 125 =head2 load 116 126 … … 123 133 if (!$self->db) { return 0 }; 124 134 125 my $sv = $self->get_global_value('schema_version') || 1; 126 if ($sv < SCHEMA_VERSION) { 127 $self->log(LA_CRIT, 128 "Schema version %d found, %d is need, please update db using " . 129 "`la-sql-upgrade' tool for `%s' base", 130 $sv, 131 SCHEMA_VERSION, 132 $self->label, 133 ); 134 # return; 135 } 135 if (!$self->IsSchemaUpToDate) { 136 my $sv = $self->get_global_value('schema_version') || 1; 137 $self->log(LA_ERR, "Schema need update, please run `la-sql-upgrade -b %s'", $self->label); 138 return; 139 } 140 136 141 if (!$self->_CreateInternalObjects) { 137 142 $self->rollback; -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/upgrade.pm
r2236 r2243 1196 1196 ], 1197 1197 }, 1198 { 1199 ver => 32, 1200 recompute => 1, 1201 } 1198 1202 ); 1199 1203 … … 1245 1249 =cut 1246 1250 1247 sub SchemaUpgrade {1251 sub _SchemaUpgrade { 1248 1252 my ($self) = @_; 1249 1253 1254 $self->log(LA_INFO, "Waiting to lock database to upgrade the schema..."); 1255 1256 $self->db->do(q{SELECT 1 FROM settings WHERE varname = 'schema_version' FOR UPDATE}); 1257 1258 $self->log(LA_INFO, "Database locked upgrading schema !"); 1259 1250 1260 return $self->temp_switch_unexported( 1251 1261 sub { … … 1268 1278 ); 1269 1279 1280 if ($self->{_base}->get_global_value('NeedRecomputeObject')) { 1281 foreach my $otype (qw(user)) { 1282 foreach my $name ($self->listRealObjects($otype)) { 1283 my $object = $self->get_object($otype, $name); 1284 $object->PostSetAttribute(); 1285 } 1286 } 1287 $self->{_base}->del_global_value('NeedRecomputeObject'); 1288 } 1289 1290 $self->commit; 1291 1270 1292 return 1; 1271 1293 } -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Task/Update.pm
r2220 r2243 18 18 =cut 19 19 20 sub order { -1 } 20 21 21 22 sub init { 22 23 my ($self) = @_; 23 24 my $LA = LATMOS::Accounts->new($self->{config}); 24 my $labase = $self->{base} ? $LA->base($self->{base}) : $LA->base; 25 $labase && $labase->load or die "Cannot load base"; 25 my $labase && $labase->_load_base($self->{base}) or die "Cannot load base"; 26 26 27 27 $self->{_la} = $LA; … … 34 34 my ($self) = @_; 35 35 36 if ($self->{_base}->get_global_value('NeedRecomputeObject')) { 37 $self->{_base}->log(LA_INFO, "NeedRecomputeObject detected, recomputing objects"); 38 } else { 39 return 1; 40 } 41 42 foreach my $otype (qw(user)) { 43 foreach my $name ($self->{_base}->listRealObjects($otype)) { 44 my $object = $self->{_base}->get_object($otype, $name); 45 $object->PostSetAttribute(); 46 $self->{_base}->commit; 47 } 48 } 49 50 $self->{_base}->del_global_value('NeedRecomputeObject'); 51 $self->{_base}->commit; 36 $self->SchemaUpgrade(); 52 37 53 38 1;
Note: See TracChangeset
for help on using the changeset viewer.