- $rr = DBA::select($table, ['id', 'data', 'backend-class', 'backend-ref'], ['`backend-class` != ?', $dest]);
- if (DBA::isResult($rr)) {
- while($r = $rr->fetch()) {
- $id = $r['id'];
- $data = $r['data'];
- $backendClass = $r['backend-class'];
- $backendRef = $r['backend-ref'];
- if ($backendClass !== '') {
- $data = $backendClass::get($backendRef);
- }
- $ref = $dest::put($data);
-
- if ($ref !== "") {
- $ru = DBA::update($table, ["backend-class" => $dest, "backend-ref" => $ref, "data" => ""], ["id" => $id]);
- if ($ru) {
- if ($backendClass !== "") {
- $backendClass::delete($backendRef);
- }
- $moved++;
+ // Get the rows where backend class is not the destination backend class
+ $resources = $this->dba->select(
+ $table,
+ ['id', 'data', 'backend-class', 'backend-ref'],
+ ['`backend-class` IS NULL or `backend-class` != ?', $destination::getName()],
+ ['limit' => $limit]
+ );
+
+ while ($resource = $this->dba->fetch($resources)) {
+ $id = $resource['id'];
+ $data = $resource['data'];
+ $source = $this->getByName($resource['backend-class']);
+ $sourceRef = $resource['backend-ref'];
+
+ if (!empty($source)) {
+ $this->logger->info('Get data from old backend.', ['oldBackend' => $source, 'oldReference' => $sourceRef]);
+ $data = $source->get($sourceRef);
+ }
+
+ $this->logger->info('Save data to new backend.', ['newBackend' => $destination]);
+ $destinationRef = $destination->put($data);
+ $this->logger->info('Saved data.', ['newReference' => $destinationRef]);
+
+ if ($destinationRef !== '') {
+ $this->logger->info('update row');
+ if ($this->dba->update($table, ['backend-class' => $destination, 'backend-ref' => $destinationRef, 'data' => ''], ['id' => $id])) {
+ if (!empty($source)) {
+ $this->logger->info('Delete data from old backend.', ['oldBackend' => $source, 'oldReference' => $sourceRef]);
+ $source->delete($sourceRef);