Skip to content

Commit 7dbde1f

Browse files
authored
#20422 #20094 adding an upgrade task to update the anonymous old email to the new one
* #20094 adding an upgrade task to update the anonymous old email to the new one * #20094 adding an upgrade task to update the anonymous old email to the new one * #20094 adding an upgrade task to update the anonymous old email to the new one * #20094 adding an upgrade task to update the anonymous old email to the new one * run-all
1 parent 5d2eed7 commit 7dbde1f

4 files changed

Lines changed: 85 additions & 0 deletions

File tree

dotCMS/src/integration-test/java/com/dotcms/MainSuite.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
import com.dotmarketing.startup.runonce.Task210319CreateStorageTableTest;
9797
import com.dotmarketing.startup.runonce.Task210321RemoveOldMetadataFilesTest;
9898
import com.dotmarketing.startup.runonce.Task210506UpdateStorageTableTest;
99+
import com.dotmarketing.startup.runonce.Task210520UpdateAnonymousEmailTest;
99100
import com.dotmarketing.startup.runonce.Task210510UpdateStorageTableDropMetadataColumnTest;
100101
import com.dotmarketing.util.ConfigTest;
101102
import com.dotmarketing.util.HashBuilderTest;
@@ -414,6 +415,8 @@
414415
FileAssetTemplateUtilTest.class,
415416
SiteSearchJobImplTest.class,
416417
Task210506UpdateStorageTableTest.class,
418+
StaticPushPublishBundleGeneratorTest.class,
419+
Task210520UpdateAnonymousEmailTest.class,
417420
Task210510UpdateStorageTableDropMetadataColumnTest.class,
418421
StaticPushPublishBundleGeneratorTest.class
419422
})
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.dotmarketing.startup.runonce;
2+
3+
import com.dotcms.util.IntegrationTestInitService;
4+
import com.dotmarketing.business.UserAPI;
5+
import com.dotmarketing.common.db.DotConnect;
6+
import com.dotmarketing.db.LocalTransaction;
7+
import org.junit.BeforeClass;
8+
import org.junit.Test;
9+
10+
import static org.junit.Assert.assertFalse;
11+
import static org.junit.Assert.assertTrue;
12+
13+
public class Task210520UpdateAnonymousEmailTest {
14+
15+
@BeforeClass
16+
public static void prepare() throws Exception {
17+
// Setting web app environment
18+
IntegrationTestInitService.getInstance().init();
19+
}
20+
21+
@Test
22+
public void testExecuteUpgrade() throws Exception {
23+
24+
LocalTransaction.wrapReturnWithListeners(()->
25+
new DotConnect().executeUpdate("UPDATE user_ SET emailaddress = ? where emailaddress = ?",
26+
Task210520UpdateAnonymousEmail.OLD_ANONYMOUS_EMAIL, UserAPI.CMS_ANON_USER_EMAIL)
27+
);
28+
29+
30+
LocalTransaction.wrapReturnWithListeners(()-> {
31+
final Task210520UpdateAnonymousEmail upgradeTask = new Task210520UpdateAnonymousEmail();
32+
assertTrue(upgradeTask.forceRun());
33+
upgradeTask.executeUpgrade();
34+
assertFalse(upgradeTask.forceRun());
35+
return null;
36+
});
37+
38+
}
39+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.dotmarketing.startup.runonce;
2+
3+
import com.dotmarketing.business.UserAPI;
4+
import com.dotmarketing.common.db.DotConnect;
5+
import com.dotmarketing.exception.DotDataException;
6+
import com.dotmarketing.exception.DotRuntimeException;
7+
import com.dotmarketing.startup.StartupTask;
8+
9+
import java.util.List;
10+
import java.util.Map;
11+
12+
/**
13+
* Updates the anonymous email to avoid the "anonymous@dotcmsfakeemail.org"
14+
* @author jsanca
15+
*/
16+
public class Task210520UpdateAnonymousEmail implements StartupTask {
17+
18+
protected static final String OLD_ANONYMOUS_EMAIL = "anonymous@dotcmsfakeemail.org";
19+
20+
@Override
21+
public boolean forceRun() {
22+
23+
try {
24+
final List<Map<String, Object>> results =
25+
new DotConnect()
26+
.setSQL("select * from user_ where emailaddress = ?")
27+
.addParam(OLD_ANONYMOUS_EMAIL)
28+
.loadObjectResults();
29+
30+
return null != results && results.size() > 0; // any result?? update the email
31+
} catch(Exception ex) {
32+
return true;
33+
}
34+
}
35+
36+
@Override
37+
public void executeUpgrade() throws DotDataException, DotRuntimeException {
38+
39+
new DotConnect().executeUpdate("UPDATE user_ SET emailaddress = ? where emailaddress = ?",
40+
UserAPI.CMS_ANON_USER_EMAIL, OLD_ANONYMOUS_EMAIL);
41+
}
42+
}

dotCMS/src/main/java/com/dotmarketing/util/TaskLocatorUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ public static List<Class<?>> getStartupRunOnceTaskClasses() {
298298
.add(Task210321RemoveOldMetadataFiles.class)
299299
.add(Task210506UpdateStorageTable.class)
300300
.add(Task210510UpdateStorageTableDropMetadataColumn.class)
301+
.add(Task210520UpdateAnonymousEmail.class)
301302
.build();
302303

303304
return ret.stream().sorted(classNameComparator).collect(Collectors.toList());

0 commit comments

Comments
 (0)