Iterate over locks and lock them if unlocked?

I have a need for some code that iterates over the locks in game and locks them if unlocked - I'm not fussed about what code or key the locks need as players nor admin need access to these locks while playing, I just want them locked and forgetten.

I need this to be something I can run once when the server runs the OnNewSave so I'm not too fussed about performance impact, and I don't see there ever being more than maybe a hundred locks in the world at run time.

How would I acheive this?

Any help appreciated, thanks in advance :)

BaseNetworkable.serverEntities will have all objects of class BaseLock.  Then SetFlag BaseEntity.Flags.Locked to true.
This worked in my testing:

				IEnumerable<BaseNetworkable> entities = BaseNetworkable.serverEntities.Where(x => x is BaseLock);
				IEnumerable<BaseNetworkable> lockables = entities.ToList();

				foreach (BaseLock lockable in lockables) {
					
					if (!lockable.IsLocked()) {
						lockable.SetFlag(BaseEntity.Flags.Locked, true);
					}
					
				}​


Will see if it does what I want when the server wipes :) thanks Zugzwang.
You could cut that down even more, if you don't need to use the list of locks anywhere else.

foreach (BaseLock lockable in BaseNetworkable.serverEntities.Where(x => x is BaseLock)) 
	lockable.SetFlag(BaseEntity.Flags.Locked, true);​

No harm in setting a flag true when it already is true.  The SetFlag method checks it automatically.

Now one thing to consider, is what happens if you lock a brand new lock, before a player makes a key or a code for it. 

Thanks, I'll change my code to slim it down a bit :)

I don't need to worry about new locks for my needs; this only runs once in OnNewSave after Pasting Back a bunch of CopyPaste bases. I noticed after pasting a structure that half the locks were unlocked... apparently a long running issue.